[Catalyst-commits] r9932 - in trunk/Catalyst-Controller-WrapCGI: .
lib/Catalyst/Controller t t/lib/TestApp/Controller
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Wed Apr 29 02:57:29 GMT 2009
Author: caelum
Date: 2009-04-29 03:57:29 +0100 (Wed, 29 Apr 2009)
New Revision: 9932
Modified:
trunk/Catalyst-Controller-WrapCGI/Changes
trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm
trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm
trunk/Catalyst-Controller-WrapCGI/t/lib/TestApp/Controller/Root.pm
trunk/Catalyst-Controller-WrapCGI/t/wrap-cgi.t
Log:
WrapCGI - file uploads support
Modified: trunk/Catalyst-Controller-WrapCGI/Changes
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/Changes 2009-04-28 22:51:34 UTC (rev 9931)
+++ trunk/Catalyst-Controller-WrapCGI/Changes 2009-04-29 02:57:29 UTC (rev 9932)
@@ -1,5 +1,8 @@
Revision history for Catalyst-Controller-WrapCGI
+ - file uploads support (caelum)
+ - test for file uploads (hdp)
+
0.0032 2009-04-27 18:43:25
- fix deps, does not work in cat 5.7 (caelum)
Modified: trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm 2009-04-28 22:51:34 UTC (rev 9931)
+++ trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm 2009-04-29 02:57:29 UTC (rev 9932)
@@ -14,7 +14,7 @@
use List::MoreUtils 'any';
use IO::File ();
use Carp;
-
+
use namespace::clean -except => 'meta';
=head1 NAME
@@ -23,11 +23,11 @@
=head1 VERSION
-Version 0.011
+Version 0.012
=cut
-our $VERSION = '0.011';
+our $VERSION = '0.012';
=head1 SYNOPSIS
Modified: trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm 2009-04-28 22:51:34 UTC (rev 9931)
+++ trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm 2009-04-29 02:57:29 UTC (rev 9932)
@@ -10,6 +10,7 @@
use URI ();
use Catalyst::Exception ();
use URI::Escape;
+use HTTP::Request::Common;
use namespace::clean -except => 'meta';
@@ -19,11 +20,11 @@
=head1 VERSION
-Version 0.0032
+Version 0.0033
=cut
-our $VERSION = '0.0032';
+our $VERSION = '0.0033';
=head1 SYNOPSIS
@@ -156,7 +157,29 @@
local $/; $body_content = <$body>;
} else {
my $body_params = $c->req->body_parameters;
- if (%$body_params) {
+
+ if (my %uploads = %{ $c->req->uploads }) {
+ my $post = POST 'http://localhost/',
+ Content_Type => 'form-data',
+ Content => [
+ %$body_params,
+ map {
+ my $upl = $uploads{$_};
+ $_ => [
+ undef,
+ $upl->filename,
+ Content => $upl->slurp,
+ 'Content-Type' => $upl->type || 'application/octet-stream',
+ map (
+ $_ => $upl->headers->header($_)
+ ), grep !/^Content-(?:Type|Disposition)$/,
+ $upl->headers->header_field_names
+ ]
+ } keys %uploads
+ ];
+ $body_content = $post->content;
+ $req->content_type($post->header('Content-Type'));
+ } elsif (%$body_params) {
my $encoder = URI->new;
$encoder->query_form(%$body_params);
$body_content = $encoder->query;
Modified: trunk/Catalyst-Controller-WrapCGI/t/lib/TestApp/Controller/Root.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/lib/TestApp/Controller/Root.pm 2009-04-28 22:51:34 UTC (rev 9931)
+++ trunk/Catalyst-Controller-WrapCGI/t/lib/TestApp/Controller/Root.pm 2009-04-29 02:57:29 UTC (rev 9932)
@@ -10,8 +10,10 @@
print $cgi->header;
print 'foo:',$cgi->param('foo'),' bar:',$cgi->param('bar');
if (my $fh = $cgi->param('baz')) {
- print 'baz:',<$fh>;
+ local $/;
+ print ' baz:',<$fh>;
}
+ die $cgi->cgi_error if $cgi->cgi_error;
};
sub handle_cgi : Path('/cgi-bin/test.cgi') {
Modified: trunk/Catalyst-Controller-WrapCGI/t/wrap-cgi.t
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/wrap-cgi.t 2009-04-28 22:51:34 UTC (rev 9931)
+++ trunk/Catalyst-Controller-WrapCGI/t/wrap-cgi.t 2009-04-29 02:57:29 UTC (rev 9932)
@@ -27,14 +27,19 @@
$response = request POST '/cgi-bin/test.cgi',
Content => [
- foo => 1, bar => 2, baz => [ undef, 'baz', Content => 3 ],
+ foo => 1,
+ bar => 2,
+ baz => [
+ undef,
+ 'baz',
+ 'Some-Header' => 'blah',
+ 'Content-Type' => 'text/plain',
+ Content => 3
+ ],
],
'Content-Type' => 'form-data';
-{
- local $TODO = 'WrapCGI does not yet construct multipart/form-data requests';
- is($response->content, 'foo:1 bar:2 baz:3', 'POST with file upload');
-}
+is($response->content, 'foo:1 bar:2 baz:3', 'POST with file upload');
$response = request '/cgi-bin/test_pathinfo.cgi/path/%2Finfo';
is($response->content, '/path/%2Finfo', 'PATH_INFO is correct');
More information about the Catalyst-commits
mailing list