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, ],
34 'Content-Type' =>'text/plain; charset=SHIFT_JIS',
35 'Content' => $string_in_shiftjis, ],
38 'Content-Type' =>'text/plain; charset=SHIFT_JIS',
39 'Content' => $string_in_shiftjis, ],
41 "$path", Encode::encode_utf8('♥ttachment.txt'), 'Content-Type' =>'text/html; charset=UTF-8'
46 ok my $env = HTTP::Message::PSGI::req_to_psgi($req);
47 ok my $fh = $env->{'psgi.input'};
48 ok my $body = HTTP::Body->new( $req->header('Content-Type'), $req->header('Content-Length') );
49 ok my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() );
50 $body->tmpdir($tempdir);
54 while ( $fh->read( my $buffer, 1024 ) ) {
58 is $body->param->{'arg0'}, 'helloworld';
59 is $body->param->{'arg1'}, $string_in_utf8;
60 is $body->param->{'arg2'}[0], $string_in_shiftjis;
61 is $body->param->{'arg2'}[1], $string_in_shiftjis;
64 $body->part_data->{'arg0'},
68 'Content-Disposition' => re(qr{^form-data\b}),
74 'arg0 part data correct',
77 $body->part_data->{'arg1'},
79 data => $string_in_utf8,
81 'Content-Disposition' => re(qr{^form-data\b}),
82 'Content-Type' => 'text/plain; charset=UTF-8',
86 size => length($string_in_utf8),
88 'arg1 part data correct',
92 $body->part_data->{'arg2'},
95 data => $string_in_shiftjis,
97 'Content-Disposition' => re(qr{^form-data\b}),
98 'Content-Type' => 'text/plain; charset=SHIFT_JIS',
102 size => length($string_in_shiftjis),
105 'arg2 part data correct',