8 use HTTP::Request::Common;
10 use File::Spec::Functions;
11 use File::Temp qw/ tempdir /;
14 eval { require HTTP::Message::PSGI };
16 skip "Plack not installed", 13 if $@;
18 my $string_for_utf8 = 'test ♥';
19 my $string_in_utf8 = Encode::encode('UTF-8',$string_for_utf8);
20 my $string_for_shiftjis = 'test テスト';
21 my $string_in_shiftjis = Encode::encode('SHIFT_JIS',$string_for_shiftjis);
22 my $path = File::Spec->catfile('t', 'utf8.txt');
24 ok my $req = POST '/root/echo_arg',
25 Content_Type => 'form-data',
30 'Content-Type' =>'text/plain; charset=UTF-8',
31 'Content' => $string_in_utf8,
35 'Content-Type' =>'text/plain; charset=SHIFT_JIS',
36 'Content' => $string_in_shiftjis,
40 'Content-Type' =>'text/plain; charset=SHIFT_JIS',
41 'Content' => $string_in_shiftjis,
44 "$path", Encode::encode_utf8('♥ttachment.txt'),
45 'Content-Type' => 'text/plain; charset=UTF-8',
46 'Content' => $string_in_utf8,
49 "$path", Encode::encode_utf8('♥ttachment.txt'), 'Content-Type' =>'text/html; charset=UTF-8'
54 ok my $env = HTTP::Message::PSGI::req_to_psgi($req);
55 ok my $fh = $env->{'psgi.input'};
56 ok my $body = HTTP::Body->new( $req->header('Content-Type'), $req->header('Content-Length') );
57 ok my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() );
58 $body->tmpdir($tempdir);
62 while ( $fh->read( my $buffer, 1024 ) ) {
66 is $body->param->{'arg0'}, 'helloworld';
67 is $body->param->{'arg1'}, $string_in_utf8;
68 is $body->param->{'arg2'}[0], $string_in_shiftjis;
69 is $body->param->{'arg2'}[1], $string_in_shiftjis;
72 $body->part_data->{'arg0'},
76 'Content-Disposition' => re(qr{^form-data\b}),
82 'arg0 part data correct',
85 $body->part_data->{'arg1'},
87 data => $string_in_utf8,
89 'Content-Disposition' => re(qr{^form-data\b}),
90 'Content-Type' => 'text/plain; charset=UTF-8',
94 size => length($string_in_utf8),
96 'arg1 part data correct',
100 $body->part_data->{'arg2'},
103 data => $string_in_shiftjis,
105 'Content-Disposition' => re(qr{^form-data\b}),
106 'Content-Type' => 'text/plain; charset=SHIFT_JIS',
110 size => length($string_in_shiftjis),
113 'arg2 part data correct',
116 my $filename = $body->upload->{'arg3'} ? ($body->upload->{'arg3'}->{tempname}||"") : "";
118 ok($filename =~ qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/, 'arg3 temp file extension correct');