Commit | Line | Data |
dd4e6fd2 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use FindBin; |
7 | use lib "$FindBin::Bin/../../lib"; |
8 | |
c4bed79a |
9 | use Test::More tests => 52; |
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 | |
fbcc39ad |
21 | my $request = POST( |
22 | 'http://localhost/dump/request/', |
23 | 'Content-Type' => 'form-data', |
dd4e6fd2 |
24 | 'Content' => [ |
fbcc39ad |
25 | 'cookies.t' => ["$FindBin::Bin/cookies.t"], |
26 | 'headers.t' => ["$FindBin::Bin/headers.t"], |
27 | 'uploads.t' => ["$FindBin::Bin/uploads.t"], |
28 | ] |
dd4e6fd2 |
29 | ); |
30 | |
31 | ok( my $response = request($request), 'Request' ); |
32 | ok( $response->is_success, 'Response Successful 2xx' ); |
fbcc39ad |
33 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
34 | like( |
35 | $response->content, |
36 | qr/^bless\( .* 'Catalyst::Request' \)$/s, |
37 | 'Content is a serialized Catalyst::Request' |
38 | ); |
39 | |
dd4e6fd2 |
40 | { |
41 | no strict 'refs'; |
fbcc39ad |
42 | ok( |
43 | eval '$creq = ' . $response->content, |
44 | 'Unserialize Catalyst::Request' |
45 | ); |
dd4e6fd2 |
46 | } |
47 | |
48 | isa_ok( $creq, 'Catalyst::Request' ); |
49 | is( $creq->method, 'POST', 'Catalyst::Request method' ); |
fbcc39ad |
50 | is( $creq->content_type, 'multipart/form-data', |
51 | 'Catalyst::Request Content-Type' ); |
52 | is( $creq->content_length, $request->content_length, |
53 | 'Catalyst::Request Content-Length' ); |
dd4e6fd2 |
54 | |
55 | for my $part ( $request->parts ) { |
56 | |
57 | my $disposition = $part->header('Content-Disposition'); |
58 | my %parameters = @{ ( split_header_words($disposition) )[0] }; |
59 | |
fbcc39ad |
60 | my $upload = $creq->{uploads}->{ $parameters{filename} }; |
61 | |
5c0ff128 |
62 | isa_ok( $upload, 'Catalyst::Request::Upload' ); |
dd4e6fd2 |
63 | |
d3fced79 |
64 | is( $upload->type, $part->content_type, 'Upload Content-Type' ); |
65 | is( $upload->size, length( $part->content ), 'Upload Content-Length' ); |
fbcc39ad |
66 | |
c4bed79a |
67 | # make sure upload is accessible via legacy params->{$file} |
68 | is( $creq->{parameters}->{ $upload->filename }, $upload->filename, 'legacy param method ok' ); |
69 | |
fbcc39ad |
70 | ok( ! -e $upload->tempname, 'Upload temp file was deleted' ); |
dd4e6fd2 |
71 | } |
dd4e6fd2 |
72 | } |
1408d0a4 |
73 | |
74 | { |
75 | my $creq; |
76 | |
fbcc39ad |
77 | my $request = POST( |
78 | 'http://localhost/dump/request/', |
1408d0a4 |
79 | 'Content-Type' => 'multipart/form-data', |
80 | 'Content' => [ |
fbcc39ad |
81 | 'testfile' => ["$FindBin::Bin/cookies.t"], |
82 | 'testfile' => ["$FindBin::Bin/headers.t"], |
83 | 'testfile' => ["$FindBin::Bin/uploads.t"], |
84 | ] |
1408d0a4 |
85 | ); |
86 | |
87 | ok( my $response = request($request), 'Request' ); |
88 | ok( $response->is_success, 'Response Successful 2xx' ); |
fbcc39ad |
89 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
90 | like( |
91 | $response->content, |
92 | qr/^bless\( .* 'Catalyst::Request' \)$/s, |
93 | 'Content is a serialized Catalyst::Request' |
94 | ); |
95 | |
1408d0a4 |
96 | { |
97 | no strict 'refs'; |
fbcc39ad |
98 | ok( |
99 | eval '$creq = ' . $response->content, |
100 | 'Unserialize Catalyst::Request' |
101 | ); |
1408d0a4 |
102 | } |
103 | |
104 | isa_ok( $creq, 'Catalyst::Request' ); |
105 | is( $creq->method, 'POST', 'Catalyst::Request method' ); |
fbcc39ad |
106 | is( $creq->content_type, 'multipart/form-data', |
107 | 'Catalyst::Request Content-Type' ); |
108 | is( $creq->content_length, $request->content_length, |
109 | 'Catalyst::Request Content-Length' ); |
110 | |
1408d0a4 |
111 | my @parts = $request->parts; |
112 | |
fbcc39ad |
113 | for ( my $i = 0 ; $i < @parts ; $i++ ) { |
114 | |
1408d0a4 |
115 | my $part = $parts[$i]; |
116 | my $disposition = $part->header('Content-Disposition'); |
117 | my %parameters = @{ ( split_header_words($disposition) )[0] }; |
fbcc39ad |
118 | |
119 | my $upload = $creq->{uploads}->{ $parameters{name} }->[$i]; |
120 | |
1408d0a4 |
121 | isa_ok( $upload, 'Catalyst::Request::Upload' ); |
122 | is( $upload->type, $part->content_type, 'Upload Content-Type' ); |
123 | is( $upload->filename, $parameters{filename}, 'Upload filename' ); |
124 | is( $upload->size, length( $part->content ), 'Upload Content-Length' ); |
fbcc39ad |
125 | |
126 | ok( ! -e $upload->tempname, 'Upload temp file was deleted' ); |
1408d0a4 |
127 | } |
128 | } |
32d4bba8 |
129 | |
130 | { |
131 | my $creq; |
132 | |
fbcc39ad |
133 | my $request = POST( |
134 | 'http://localhost/engine/request/uploads/slurp', |
32d4bba8 |
135 | 'Content-Type' => 'multipart/form-data', |
fbcc39ad |
136 | 'Content' => [ 'slurp' => ["$FindBin::Bin/uploads.t"], ] |
32d4bba8 |
137 | ); |
138 | |
139 | ok( my $response = request($request), 'Request' ); |
140 | ok( $response->is_success, 'Response Successful 2xx' ); |
141 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
fbcc39ad |
142 | is( $response->content, ( $request->parts )[0]->content, 'Content' ); |
32d4bba8 |
143 | } |