8 use HTTP::Request::Common;
10 use HTTP::Message::PSGI ();
11 use File::Spec::Functions;
12 use File::Temp qw/ tempdir /;
15 eval { require HTTP::Message::PSGI };
17 skip "Plack not installed", 13 if $@;
19 my $string_for_utf8 = 'test ♥';
20 my $string_in_utf8 = Encode::encode('UTF-8',$string_for_utf8);
21 my $string_for_shiftjis = 'test テスト';
22 my $string_in_shiftjis = Encode::encode('SHIFT_JIS',$string_for_shiftjis);
23 my $path = File::Spec->catfile('t', 'utf8.txt');
25 ok my $req = POST '/root/echo_arg',
26 Content_Type => 'form-data',
31 'Content-Type' =>'text/plain; charset=UTF-8',
32 'Content' => $string_in_utf8, ],
35 'Content-Type' =>'text/plain; charset=SHIFT_JIS',
36 'Content' => $string_in_shiftjis, ],
39 'Content-Type' =>'text/plain; charset=SHIFT_JIS',
40 'Content' => $string_in_shiftjis, ],
42 "$path", Encode::encode_utf8('♥ttachment.txt'), 'Content-Type' =>'text/html; charset=UTF-8'
47 ok my $env = HTTP::Message::PSGI::req_to_psgi($req);
48 ok my $fh = $env->{'psgi.input'};
49 ok my $body = HTTP::Body->new( $req->header('Content-Type'), $req->header('Content-Length') );
50 ok my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() );
51 $body->tmpdir($tempdir);
55 while ( $fh->read( my $buffer, 1024 ) ) {
59 is $body->param->{'arg0'}, 'helloworld';
60 is $body->param->{'arg1'}, $string_in_utf8;
61 is $body->param->{'arg2'}[0], $string_in_shiftjis;
62 is $body->param->{'arg2'}[1], $string_in_shiftjis;
65 $body->part_data->{'arg0'},
69 'Content-Disposition' => re(qr{^form-data\b}),
75 'arg0 part data correct',
78 $body->part_data->{'arg1'},
80 data => $string_in_utf8,
82 'Content-Disposition' => re(qr{^form-data\b}),
83 'Content-Type' => 'text/plain; charset=UTF-8',
87 size => length($string_in_utf8),
89 'arg1 part data correct',
93 $body->part_data->{'arg2'},
96 data => $string_in_shiftjis,
98 'Content-Disposition' => re(qr{^form-data\b}),
99 'Content-Type' => 'text/plain; charset=SHIFT_JIS',
103 size => length($string_in_shiftjis),
106 'arg2 part data correct',