Commit | Line | Data |
dd4e6fd2 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use FindBin; |
7 | use lib "$FindBin::Bin/../../lib"; |
8 | |
1408d0a4 |
9 | use Test::More tests => 39; |
dd4e6fd2 |
10 | use Catalyst::Test 'TestApp'; |
11 | |
12 | use Catalyst::Request; |
5c0ff128 |
13 | use Catalyst::Request::Upload; |
dd4e6fd2 |
14 | use HTTP::Headers; |
15 | use HTTP::Headers::Util 'split_header_words'; |
16 | use HTTP::Request::Common; |
17 | |
18 | { |
19 | my $creq; |
20 | |
21 | my $request = POST( 'http://localhost/dump/request/', |
22 | 'Content-Type' => 'multipart/form-data', |
23 | 'Content' => [ |
24 | 'cookies.t' => [ "$FindBin::Bin/cookies.t" ], |
25 | 'headers.t' => [ "$FindBin::Bin/headers.t" ], |
26 | 'uploads.t' => [ "$FindBin::Bin/uploads.t" ], |
27 | ] |
28 | ); |
29 | |
30 | ok( my $response = request($request), 'Request' ); |
31 | ok( $response->is_success, 'Response Successful 2xx' ); |
06e1b616 |
32 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
dd4e6fd2 |
33 | like( $response->content, qr/^bless\( .* 'Catalyst::Request' \)$/s, 'Content is a serialized Catalyst::Request' ); |
3b242e4f |
34 | |
dd4e6fd2 |
35 | { |
36 | no strict 'refs'; |
37 | ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' ); |
38 | } |
39 | |
40 | isa_ok( $creq, 'Catalyst::Request' ); |
41 | is( $creq->method, 'POST', 'Catalyst::Request method' ); |
42 | is( $creq->content_type, 'multipart/form-data', 'Catalyst::Request Content-Type' ); |
43 | is( $creq->content_length, $request->content_length, 'Catalyst::Request Content-Length' ); |
44 | |
45 | for my $part ( $request->parts ) { |
46 | |
47 | my $disposition = $part->header('Content-Disposition'); |
48 | my %parameters = @{ ( split_header_words($disposition) )[0] }; |
49 | |
50 | my $upload = $creq->uploads->{ $parameters{filename} }; |
5c0ff128 |
51 | |
52 | isa_ok( $upload, 'Catalyst::Request::Upload' ); |
dd4e6fd2 |
53 | |
d3fced79 |
54 | is( $upload->type, $part->content_type, 'Upload Content-Type' ); |
55 | is( $upload->size, length( $part->content ), 'Upload Content-Length' ); |
dd4e6fd2 |
56 | } |
dd4e6fd2 |
57 | } |
1408d0a4 |
58 | |
59 | { |
60 | my $creq; |
61 | |
62 | my $request = POST( 'http://localhost/dump/request/', |
63 | 'Content-Type' => 'multipart/form-data', |
64 | 'Content' => [ |
65 | 'testfile' => [ "$FindBin::Bin/cookies.t" ], |
66 | 'testfile' => [ "$FindBin::Bin/headers.t" ], |
67 | 'testfile' => [ "$FindBin::Bin/uploads.t" ], |
68 | ] |
69 | ); |
70 | |
71 | ok( my $response = request($request), 'Request' ); |
72 | ok( $response->is_success, 'Response Successful 2xx' ); |
73 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
74 | like( $response->content, qr/^bless\( .* 'Catalyst::Request' \)$/s, 'Content is a serialized Catalyst::Request' ); |
75 | |
76 | { |
77 | no strict 'refs'; |
78 | ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' ); |
79 | } |
80 | |
81 | isa_ok( $creq, 'Catalyst::Request' ); |
82 | is( $creq->method, 'POST', 'Catalyst::Request method' ); |
83 | is( $creq->content_type, 'multipart/form-data', 'Catalyst::Request Content-Type' ); |
84 | is( $creq->content_length, $request->content_length, 'Catalyst::Request Content-Length' ); |
85 | |
86 | my @parts = $request->parts; |
87 | |
88 | for ( my $i = 0; $i < @parts; $i++ ) { |
89 | |
90 | my $part = $parts[$i]; |
91 | my $disposition = $part->header('Content-Disposition'); |
92 | my %parameters = @{ ( split_header_words($disposition) )[0] }; |
93 | |
94 | my $upload = $creq->uploads->{ $parameters{name} }->[$i]; |
95 | |
96 | isa_ok( $upload, 'Catalyst::Request::Upload' ); |
97 | is( $upload->type, $part->content_type, 'Upload Content-Type' ); |
98 | is( $upload->filename, $parameters{filename}, 'Upload filename' ); |
99 | is( $upload->size, length( $part->content ), 'Upload Content-Length' ); |
100 | } |
101 | } |