Mercurial > hg > nginx-tests
comparison perl.t @ 1152:8241ebbe753d
Tests: added perl header_out content-length tests with ranges.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 24 Mar 2017 15:25:46 +0300 |
parents | 882267679006 |
children | a69de1aba1ad |
comparison
equal
deleted
inserted
replaced
1151:57673c7257a3 | 1152:8241ebbe753d |
---|---|
21 ############################################################################### | 21 ############################################################################### |
22 | 22 |
23 select STDERR; $| = 1; | 23 select STDERR; $| = 1; |
24 select STDOUT; $| = 1; | 24 select STDOUT; $| = 1; |
25 | 25 |
26 my $t = Test::Nginx->new()->has(qw/http perl rewrite/)->plan(13) | 26 my $t = Test::Nginx->new()->has(qw/http perl rewrite/)->plan(16) |
27 ->write_file_expand('nginx.conf', <<'EOF'); | 27 ->write_file_expand('nginx.conf', <<'EOF'); |
28 | 28 |
29 %%TEST_GLOBALS%% | 29 %%TEST_GLOBALS%% |
30 | 30 |
31 daemon off; | 31 daemon off; |
58 | 58 |
59 $r->print("host: ", $r->header_in("Host"), "\n"); | 59 $r->print("host: ", $r->header_in("Host"), "\n"); |
60 $r->print("xfoo: ", $r->header_in("X-Foo"), "\n"); | 60 $r->print("xfoo: ", $r->header_in("X-Foo"), "\n"); |
61 $r->print("cookie: ", $r->header_in("Cookie"), "\n"); | 61 $r->print("cookie: ", $r->header_in("Cookie"), "\n"); |
62 $r->print("xff: ", $r->header_in("X-Forwarded-For"), "\n"); | 62 $r->print("xff: ", $r->header_in("X-Forwarded-For"), "\n"); |
63 | |
64 return OK; | |
65 }'; | |
66 } | |
67 | |
68 location /range { | |
69 perl 'sub { | |
70 use warnings; | |
71 use strict; | |
72 | |
73 my $r = shift; | |
74 | |
75 $r->header_out("Content-Length", "42"); | |
76 $r->allow_ranges(); | |
77 $r->send_http_header("text/plain"); | |
78 | |
79 return OK if $r->header_only; | |
80 | |
81 $r->print("x" x 42); | |
63 | 82 |
64 return OK; | 83 return OK; |
65 }'; | 84 }'; |
66 } | 85 } |
67 | 86 |
134 . 'X-Forwarded-For: foo1' . CRLF | 153 . 'X-Forwarded-For: foo1' . CRLF |
135 . 'X-Forwarded-For: foo2' . CRLF | 154 . 'X-Forwarded-For: foo2' . CRLF |
136 . 'Host: localhost' . CRLF . CRLF | 155 . 'Host: localhost' . CRLF . CRLF |
137 ), qr/xff: foo1, foo2/, 'perl header_in xff2'); | 156 ), qr/xff: foo1, foo2/, 'perl header_in xff2'); |
138 | 157 |
158 # headers_out content-length tests with range filter | |
159 | |
160 like(http_get('/range'), qr/Content-Length: 42.*^x{42}$/ms, | |
161 'perl header_out content-length'); | |
162 | |
163 like(http( | |
164 'GET /range HTTP/1.0' . CRLF | |
165 . 'Host: localhost' . CRLF | |
166 . 'Range: bytes=0-1' . CRLF . CRLF | |
167 ), qr/Content-Length: 2.*^xx$/ms, 'perl header_out content-length range'); | |
168 | |
169 like(http( | |
170 'GET /range HTTP/1.0' . CRLF | |
171 . 'Host: localhost' . CRLF | |
172 . 'Range: bytes=0-1,3-5' . CRLF . CRLF | |
173 ), qr/Content-Length: (?!42).*^xx\x0d.*^xxx\x0d/ms, | |
174 'perl header_out content-length multipart'); | |
175 | |
139 # various request body tests | 176 # various request body tests |
140 | 177 |
141 like(http( | 178 like(http( |
142 'GET /body HTTP/1.0' . CRLF | 179 'GET /body HTTP/1.0' . CRLF |
143 . 'Host: localhost' . CRLF | 180 . 'Host: localhost' . CRLF |