8 use HTTP::Request::Common;
10 use HTTP::Message::PSGI ();
11 use File::Spec::Functions;
12 use File::Temp qw/ tempdir /;
15 my $string_for_utf8 = 'test ♥';
16 my $string_in_utf8 = Encode::encode('UTF-8',$string_for_utf8);
17 my $string_for_shiftjis = 'test テスト';
18 my $string_in_shiftjis = Encode::encode('SHIFT_JIS',$string_for_shiftjis);
19 my $path = File::Spec->catfile('t', 'utf8.txt');
21 ok my $req = POST '/root/echo_arg',
22 Content_Type => 'form-data',
27 'Content-Type' =>'text/plain; charset=UTF-8',
28 'Content' => $string_in_utf8, ],
31 'Content-Type' =>'text/plain; charset=SHIFT_JIS',
32 'Content' => $string_in_shiftjis, ],
35 'Content-Type' =>'text/plain; charset=SHIFT_JIS',
36 'Content' => $string_in_shiftjis, ],
38 "$path", Encode::encode_utf8('♥ttachment.txt'), 'Content-Type' =>'text/html; charset=UTF-8'
43 ok my $env = HTTP::Message::PSGI::req_to_psgi($req);
44 ok my $fh = $env->{'psgi.input'};
45 ok my $body = HTTP::Body->new( $req->header('Content-Type'), $req->header('Content-Length') );
46 ok my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() );
47 $body->tmpdir($tempdir);
51 while ( $fh->read( my $buffer, 1024 ) ) {
55 is $body->param->{'arg0'}, 'helloworld';
56 is $body->param->{'arg1'}, $string_in_utf8;
57 is $body->param->{'arg2'}[0], $string_in_shiftjis;
58 is $body->param->{'arg2'}[1], $string_in_shiftjis;
61 $body->part_data->{'arg0'},
65 'Content-Disposition' => re(qr{^form-data\b}),
71 'arg0 part data correct',
74 $body->part_data->{'arg1'},
76 data => $string_in_utf8,
78 'Content-Disposition' => re(qr{^form-data\b}),
79 'Content-Type' => 'text/plain; charset=UTF-8',
83 size => length($string_in_utf8),
85 'arg1 part data correct',
89 $body->part_data->{'arg2'},
92 data => $string_in_shiftjis,
94 'Content-Disposition' => re(qr{^form-data\b}),
95 'Content-Type' => 'text/plain; charset=SHIFT_JIS',
99 size => length($string_in_shiftjis),
102 'arg2 part data correct',