Mercurial > hg > ngx_http_delay_body_filter_module
comparison t/delay_body.t @ 0:a386f95c5ae9
Initial module skeleton.
Mostly based on catch body filter. Does not work yet.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 17 Aug 2021 22:51:56 +0300 |
parents | |
children | 7c2d64d9c656 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a386f95c5ae9 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for delay body filter module. | |
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/) | |
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 delay_body 1s; | |
40 add_header X-Time $request_time; | |
41 proxy_pass http://127.0.0.1:8080/empty; | |
42 } | |
43 location /empty { | |
44 return 200 "test response body\n"; | |
45 } | |
46 } | |
47 } | |
48 | |
49 EOF | |
50 | |
51 $t->try_run('no delay_body')->plan(4); | |
52 | |
53 ############################################################################### | |
54 | |
55 like(get_body('/', '123456'), qr/200 OK.*X-Time: 1/ms, 'delay'); | |
56 like(get_body('/empty', '123456'), qr/200 OK.*X-Time: 0/ms, 'no delay'); | |
57 | |
58 # pipelining | |
59 | |
60 like(get_body('/', '123456', '12345X'), | |
61 qr/200 OK.*X-Time: 1.*200 OK.*X-Time: 1/ms, | |
62 'pipelining delay'); | |
63 | |
64 # pipelining with chunked | |
65 | |
66 like(get_chunked('/', '123456', '12345X'), | |
67 qr/200 OK.*X-Time: 1.*200 OK.*X-Time: 1/ms, | |
68 'pipelining chunked delay'); | |
69 | |
70 ############################################################################### | |
71 | |
72 sub get_body { | |
73 my $uri = shift; | |
74 my $last = pop; | |
75 return http( join '', (map { | |
76 my $body = $_; | |
77 "GET $uri HTTP/1.1" . CRLF | |
78 . "Host: localhost" . CRLF | |
79 . "Content-Length: " . (length $body) . CRLF . CRLF | |
80 . $body | |
81 } @_), | |
82 "GET $uri HTTP/1.1" . CRLF | |
83 . "Host: localhost" . CRLF | |
84 . "Connection: close" . CRLF | |
85 . "Content-Length: " . (length $last) . CRLF . CRLF | |
86 . $last | |
87 ); | |
88 } | |
89 | |
90 sub get_chunked { | |
91 my $uri = shift; | |
92 my $last = pop; | |
93 return http( join '', (map { | |
94 my $body = $_; | |
95 "GET $uri HTTP/1.1" . CRLF | |
96 . "Host: localhost" . CRLF | |
97 . "Transfer-Encoding: chunked" . CRLF . CRLF | |
98 . sprintf("%x", length $body) . CRLF | |
99 . $body . CRLF | |
100 . "0" . CRLF . CRLF | |
101 } @_), | |
102 "GET $uri HTTP/1.1" . CRLF | |
103 . "Host: localhost" . CRLF | |
104 . "Connection: close" . CRLF | |
105 . "Transfer-Encoding: chunked" . CRLF . CRLF | |
106 . sprintf("%x", length $last) . CRLF | |
107 . $last . CRLF | |
108 . "0" . CRLF . CRLF | |
109 ); | |
110 } | |
111 | |
112 ############################################################################### |