Mercurial > hg > ngx_http_catch_body_filter_module
comparison t/buffering.t @ 3:d7b8639a8857
Tests for "proxy_request_buffering off".
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 09 Feb 2015 16:33:13 +0300 |
parents | |
children | 01a36878bf36 |
comparison
equal
deleted
inserted
replaced
2:04788ce8dae7 | 3:d7b8639a8857 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for "proxy_request_buffering off". | |
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 | |
22 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(1) | |
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 | |
39 location / { | |
40 proxy_pass http://127.0.0.1:8080/catch; | |
41 proxy_request_buffering off; | |
42 add_header X-Request-Time $request_time always; | |
43 } | |
44 | |
45 location /catch { | |
46 proxy_pass http://127.0.0.1:8080/proxy; | |
47 proxy_request_buffering off; | |
48 catch_body on; | |
49 } | |
50 | |
51 location /proxy { | |
52 proxy_pass http://127.0.0.1:8080/empty; | |
53 } | |
54 | |
55 location /empty { | |
56 return 200 "test response body\n"; | |
57 } | |
58 } | |
59 } | |
60 | |
61 EOF | |
62 | |
63 $t->write_file('index.html', 'SEE-THIS'); | |
64 $t->run(); | |
65 | |
66 ############################################################################### | |
67 | |
68 # buffering switched off - expect immediate reject, | |
69 # before we'll send second part of the body | |
70 | |
71 like(get_sleep('/', '12345X', '123456'), | |
72 qr/403 Forbidden.*X-Request-Time: 0/ms, | |
73 'unbuffered request rejected'); | |
74 | |
75 ############################################################################### | |
76 | |
77 sub get_sleep { | |
78 my $uri = shift; | |
79 my $first = shift; | |
80 my $second = shift; | |
81 my $length = length($first) + length($second); | |
82 return http( | |
83 "GET $uri HTTP/1.1" . CRLF | |
84 . "Host: localhost" . CRLF | |
85 . "Connection: close" . CRLF | |
86 . "Content-Length: $length" . CRLF . CRLF | |
87 . $first, | |
88 sleep => 1.1, | |
89 body => $second | |
90 ); | |
91 } | |
92 | |
93 ############################################################################### |