Mercurial > hg > nginx-tests
annotate sub_filter_buffering.t @ 1855:b3bbde3f806d
Tests: HTTP/2 tests with error_page and return.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 11 May 2023 15:29:41 +0400 |
parents | 9d579fc770a6 |
children |
rev | line source |
---|---|
975
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for sub_filter buffering. |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 use Socket qw/ CRLF /; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 |
1417
ea796652fcdc
Tests: added missing proxy prerequisites.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1070
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http sub proxy/)->plan(2) |
975
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 events { |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 } |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 http { |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 server { |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 listen 127.0.0.1:8080; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 server_name localhost; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 proxy_buffering off; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 proxy_http_version 1.1; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 sub_filter_types *; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 location /partial { |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 proxy_pass http://127.0.0.1:8081; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 sub_filter za ZA; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 } |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 location /negative { |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 proxy_pass http://127.0.0.1:8081; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 sub_filter ab AB; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 } |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 } |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 } |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 EOF |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 $t->run_daemon(\&http_daemon); |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 ############################################################################### |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 # partial match: the last byte matching pattern is buffered |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 like(http_get('/partial'), qr/xy$/, 'partial match'); |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 # no partial match: an entire buffer is sent as is without buffering |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 like(http_get('/negative'), qr/xyz/, 'negative match'); |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 ############################################################################### |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 sub http_daemon { |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 my $server = IO::Socket::INET->new( |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 Proto => 'tcp', |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 LocalHost => '127.0.0.1:' . port(8081), |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 Listen => 5, |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 Reuse => 1 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 ) |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 or die "Can't create listening socket: $!\n"; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 local $SIG{PIPE} = 'IGNORE'; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 while (my $client = $server->accept()) { |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 $client->autoflush(1); |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
91 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
92 while (<$client>) { |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 last if /^\x0d?\x0a?$/; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 } |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
95 |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
96 print $client |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
97 "HTTP/1.1 200 OK" . CRLF . |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 "Content-Length: 10" . CRLF . CRLF . |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
99 "xyz"; |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
100 } |
e17ffab3febc
Tests: sub_filter tests with buffering.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
101 } |
1451 | 102 |
103 ############################################################################### |