Mercurial > hg > nginx-tests
comparison perl.t @ 282:04832fc79805
Tests: perl request body testing.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 23 Apr 2013 11:33:40 +0400 |
parents | 6a0d934950bc |
children | 484b713f57b0 |
comparison
equal
deleted
inserted
replaced
281:53068d38a3ce | 282:04832fc79805 |
---|---|
9 use warnings; | 9 use warnings; |
10 use strict; | 10 use strict; |
11 | 11 |
12 use Test::More; | 12 use Test::More; |
13 | 13 |
14 use Socket qw/ CRLF /; | |
15 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | 16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
15 | 17 |
16 use lib 'lib'; | 18 use lib 'lib'; |
17 use Test::Nginx; | 19 use Test::Nginx; |
18 | 20 |
19 ############################################################################### | 21 ############################################################################### |
20 | 22 |
21 select STDERR; $| = 1; | 23 select STDERR; $| = 1; |
22 select STDOUT; $| = 1; | 24 select STDOUT; $| = 1; |
23 | 25 |
24 my $t = Test::Nginx->new()->has(qw/http perl rewrite/)->plan(1) | 26 my $t = Test::Nginx->new()->has(qw/http perl rewrite/)->plan(7) |
25 ->write_file_expand('nginx.conf', <<'EOF'); | 27 ->write_file_expand('nginx.conf', <<'EOF'); |
26 | 28 |
27 %%TEST_GLOBALS%% | 29 %%TEST_GLOBALS%% |
28 | 30 |
29 daemon off; | 31 daemon off; |
55 $r->print("$v"); | 57 $r->print("$v"); |
56 | 58 |
57 return OK; | 59 return OK; |
58 }'; | 60 }'; |
59 } | 61 } |
62 | |
63 location /body { | |
64 perl 'sub { | |
65 use warnings; | |
66 use strict; | |
67 | |
68 my $r = shift; | |
69 | |
70 if ($r->has_request_body(\&post)) { | |
71 return OK; | |
72 } | |
73 | |
74 return HTTP_BAD_REQUEST; | |
75 | |
76 sub post { | |
77 my $r = shift; | |
78 $r->send_http_header; | |
79 $r->print("body: ", $r->request_body, "\n"); | |
80 $r->print("file: ", $r->request_body_file, "\n"); | |
81 } | |
82 }'; | |
83 } | |
60 } | 84 } |
61 } | 85 } |
62 | 86 |
63 EOF | 87 EOF |
64 | 88 |
66 | 90 |
67 ############################################################################### | 91 ############################################################################### |
68 | 92 |
69 like(http_get('/'), qr/TEST/, 'perl response'); | 93 like(http_get('/'), qr/TEST/, 'perl response'); |
70 | 94 |
95 like(http( | |
96 'GET /body HTTP/1.0' . CRLF | |
97 . 'Host: localhost' . CRLF | |
98 . 'Content-Length: 10' . CRLF . CRLF | |
99 . '1234567890' | |
100 ), qr/body: 1234567890/, 'perl body preread'); | |
101 | |
102 like(http( | |
103 'GET /body HTTP/1.0' . CRLF | |
104 . 'Host: localhost' . CRLF | |
105 . 'Content-Length: 10' . CRLF . CRLF, | |
106 sleep => 0.1, | |
107 body => '1234567890' | |
108 ), qr/body: 1234567890/, 'perl body late'); | |
109 | |
110 TODO: { | |
111 local $TODO = 'broken' if $t->has_version('1.3.9'); | |
112 | |
113 like(http( | |
114 'GET /body HTTP/1.0' . CRLF | |
115 . 'Host: localhost' . CRLF | |
116 . 'Content-Length: 10' . CRLF . CRLF | |
117 . '12345', | |
118 sleep => 0.1, | |
119 body => '67890' | |
120 ), qr/body: 1234567890/, 'perl body split'); | |
121 | |
122 } | |
123 | |
124 TODO: { | |
125 local $TODO = 'not yet'; | |
126 | |
127 like(http( | |
128 'GET /body HTTP/1.1' . CRLF | |
129 . 'Host: localhost' . CRLF | |
130 . 'Connection: close' . CRLF | |
131 . 'Transfer-Encoding: chunked' . CRLF . CRLF | |
132 . 'a' . CRLF | |
133 . '1234567890' . CRLF | |
134 . '0' . CRLF . CRLF | |
135 ), qr/body: 1234567890/, 'perl body chunked'); | |
136 | |
137 like(http( | |
138 'GET /body HTTP/1.1' . CRLF | |
139 . 'Host: localhost' . CRLF | |
140 . 'Connection: close' . CRLF | |
141 . 'Transfer-Encoding: chunked' . CRLF . CRLF, | |
142 sleep => 0.1, | |
143 body => 'a' . CRLF . '1234567890' . CRLF . '0' . CRLF . CRLF | |
144 ), qr/body: 1234567890/, 'perl body chunked late'); | |
145 | |
146 like(http( | |
147 'GET /body HTTP/1.1' . CRLF | |
148 . 'Host: localhost' . CRLF | |
149 . 'Connection: close' . CRLF | |
150 . 'Transfer-Encoding: chunked' . CRLF . CRLF | |
151 . 'a' . CRLF | |
152 . '12345', | |
153 sleep => 0.1, | |
154 body => '67890' . CRLF . '0' . CRLF . CRLF | |
155 ), qr/body: 1234567890/, 'perl body chunked split'); | |
156 | |
157 } | |
158 | |
71 ############################################################################### | 159 ############################################################################### |