Commit | Line | Data |
dd4e6fd2 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use FindBin; |
7 | use lib "$FindBin::Bin/../../lib"; |
8 | |
fbcc39ad |
9 | use Test::More tests => 49; |
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 | |
67 | ok( ! -e $upload->tempname, 'Upload temp file was deleted' ); |
dd4e6fd2 |
68 | } |
dd4e6fd2 |
69 | } |
1408d0a4 |
70 | |
71 | { |
72 | my $creq; |
73 | |
fbcc39ad |
74 | my $request = POST( |
75 | 'http://localhost/dump/request/', |
1408d0a4 |
76 | 'Content-Type' => 'multipart/form-data', |
77 | 'Content' => [ |
fbcc39ad |
78 | 'testfile' => ["$FindBin::Bin/cookies.t"], |
79 | 'testfile' => ["$FindBin::Bin/headers.t"], |
80 | 'testfile' => ["$FindBin::Bin/uploads.t"], |
81 | ] |
1408d0a4 |
82 | ); |
83 | |
84 | ok( my $response = request($request), 'Request' ); |
85 | ok( $response->is_success, 'Response Successful 2xx' ); |
fbcc39ad |
86 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
87 | like( |
88 | $response->content, |
89 | qr/^bless\( .* 'Catalyst::Request' \)$/s, |
90 | 'Content is a serialized Catalyst::Request' |
91 | ); |
92 | |
1408d0a4 |
93 | { |
94 | no strict 'refs'; |
fbcc39ad |
95 | ok( |
96 | eval '$creq = ' . $response->content, |
97 | 'Unserialize Catalyst::Request' |
98 | ); |
1408d0a4 |
99 | } |
100 | |
101 | isa_ok( $creq, 'Catalyst::Request' ); |
102 | is( $creq->method, 'POST', 'Catalyst::Request method' ); |
fbcc39ad |
103 | is( $creq->content_type, 'multipart/form-data', |
104 | 'Catalyst::Request Content-Type' ); |
105 | is( $creq->content_length, $request->content_length, |
106 | 'Catalyst::Request Content-Length' ); |
107 | |
1408d0a4 |
108 | my @parts = $request->parts; |
109 | |
fbcc39ad |
110 | for ( my $i = 0 ; $i < @parts ; $i++ ) { |
111 | |
1408d0a4 |
112 | my $part = $parts[$i]; |
113 | my $disposition = $part->header('Content-Disposition'); |
114 | my %parameters = @{ ( split_header_words($disposition) )[0] }; |
fbcc39ad |
115 | |
116 | my $upload = $creq->{uploads}->{ $parameters{name} }->[$i]; |
117 | |
1408d0a4 |
118 | isa_ok( $upload, 'Catalyst::Request::Upload' ); |
119 | is( $upload->type, $part->content_type, 'Upload Content-Type' ); |
120 | is( $upload->filename, $parameters{filename}, 'Upload filename' ); |
121 | is( $upload->size, length( $part->content ), 'Upload Content-Length' ); |
fbcc39ad |
122 | |
123 | ok( ! -e $upload->tempname, 'Upload temp file was deleted' ); |
1408d0a4 |
124 | } |
125 | } |
32d4bba8 |
126 | |
127 | { |
128 | my $creq; |
129 | |
fbcc39ad |
130 | my $request = POST( |
131 | 'http://localhost/engine/request/uploads/slurp', |
32d4bba8 |
132 | 'Content-Type' => 'multipart/form-data', |
fbcc39ad |
133 | 'Content' => [ 'slurp' => ["$FindBin::Bin/uploads.t"], ] |
32d4bba8 |
134 | ); |
135 | |
136 | ok( my $response = request($request), 'Request' ); |
137 | ok( $response->is_success, 'Response Successful 2xx' ); |
138 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
fbcc39ad |
139 | is( $response->content, ( $request->parts )[0]->content, 'Content' ); |
32d4bba8 |
140 | } |