Mercurial > hg > ngx_http_catch_body_filter_module
annotate t/catch_body.t @ 5:ae29daca3f0e default tip
Explicit use of "proxy_request_buffering on" in tests.
This allows to avoid spurious tests failures in test runs with request
buffering switched off by default.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 06 Mar 2015 17:44:38 +0300 |
parents | 01a36878bf36 |
children |
rev | line source |
---|---|
0 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
1 | 5 # Tests for catch body filter module. |
0 | 6 |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 use Test::Nginx; | |
14 | |
15 use Socket qw/ CRLF /; | |
16 | |
17 ############################################################################### | |
18 | |
19 select STDERR; $| = 1; | |
20 select STDOUT; $| = 1; | |
21 | |
4 | 22 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/) |
0 | 23 ->write_file_expand('nginx.conf', <<'EOF'); |
24 | |
25 %%TEST_GLOBALS%% | |
26 | |
27 daemon off; | |
28 | |
29 events { | |
30 } | |
31 | |
32 http { | |
33 %%TEST_GLOBALS_HTTP%% | |
34 | |
35 server { | |
36 listen 127.0.0.1:8080; | |
37 server_name localhost; | |
38 location / { | |
39 catch_body on; | |
40 proxy_pass http://127.0.0.1:8080/empty; | |
41 } | |
42 location /empty { | |
43 return 200 "test response body\n"; | |
44 } | |
45 } | |
46 } | |
47 | |
48 EOF | |
49 | |
50 $t->write_file('index.html', 'SEE-THIS'); | |
4 | 51 $t->try_run('no catch_body')->plan(6); |
0 | 52 |
53 ############################################################################### | |
54 | |
55 like(get_body('/', '123456'), qr/200 OK/, 'normal'); | |
56 like(get_body('/', '12345X'), qr/403 Forbidden/, 'rejected'); | |
57 | |
58 # pipelining | |
59 | |
60 like(get_body('/', '123456', '12345X'), | |
61 qr/200 OK.*403 Forbidden/ms, | |
62 'second rejected'); | |
63 | |
64 like(get_body('/', '123456' x 1024, '12345X6789' x 1024, '123456' x 1024), | |
2
04788ce8dae7
Close connection on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
65 qr/200 OK.*403 Forbidden(?!.*400 Bad)/ms, |
04788ce8dae7
Close connection on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
66 'accepted rejected ignored'); |
0 | 67 |
68 # pipelining with chunked | |
69 | |
70 like(get_chunked('/', '123456', '12345X'), | |
71 qr/200 OK.*403 Forbidden/ms, | |
2
04788ce8dae7
Close connection on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
72 'chunked second rejected'); |
0 | 73 |
74 like(get_chunked('/', '123456', '12345X6789', '123456'), | |
2
04788ce8dae7
Close connection on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
75 qr/200 OK.*403 Forbidden(?!.*400 Bad)/ms, |
04788ce8dae7
Close connection on errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
76 'chunked accepted rejected ignored'); |
0 | 77 |
78 ############################################################################### | |
79 | |
80 sub get_body { | |
81 my $uri = shift; | |
82 my $last = pop; | |
83 return http( join '', (map { | |
84 my $body = $_; | |
85 "GET $uri HTTP/1.1" . CRLF | |
86 . "Host: localhost" . CRLF | |
87 . "Content-Length: " . (length $body) . CRLF . CRLF | |
88 . $body | |
89 } @_), | |
90 "GET $uri HTTP/1.1" . CRLF | |
91 . "Host: localhost" . CRLF | |
92 . "Connection: close" . CRLF | |
93 . "Content-Length: " . (length $last) . CRLF . CRLF | |
94 . $last | |
95 ); | |
96 } | |
97 | |
98 sub get_chunked { | |
99 my $uri = shift; | |
100 my $last = pop; | |
101 return http( join '', (map { | |
102 my $body = $_; | |
103 "GET $uri HTTP/1.1" . CRLF | |
104 . "Host: localhost" . CRLF | |
105 . "Transfer-Encoding: chunked" . CRLF . CRLF | |
106 . sprintf("%x", length $body) . CRLF | |
107 . $body . CRLF | |
108 . "0" . CRLF . CRLF | |
109 } @_), | |
110 "GET $uri HTTP/1.1" . CRLF | |
111 . "Host: localhost" . CRLF | |
112 . "Connection: close" . CRLF | |
113 . "Transfer-Encoding: chunked" . CRLF . CRLF | |
114 . sprintf("%x", length $last) . CRLF | |
115 . $last . CRLF | |
116 . "0" . CRLF . CRLF | |
117 ); | |
118 } | |
119 | |
120 ############################################################################### |