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)
use List::MoreUtils 'any';
use IO::File ();
use Carp;
-
+
use namespace::clean -except => 'meta';
=head1 NAME
=head1 VERSION
-Version 0.011
+Version 0.012
=cut
-our $VERSION = '0.011';
+our $VERSION = '0.012';
=head1 SYNOPSIS
use URI ();
use Catalyst::Exception ();
use URI::Escape;
+use HTTP::Request::Common;
use namespace::clean -except => 'meta';
=head1 VERSION
-Version 0.0032
+Version 0.0033
=cut
-our $VERSION = '0.0032';
+our $VERSION = '0.0033';
=head1 SYNOPSIS
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;
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') {
$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');