Mercurial > hg > nginx-tests
annotate proxy_chunked_extra.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 5ac6efbe5552 |
children |
rev | line source |
---|---|
1581
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 # Test for http backend returning response with Transfer-Encoding: chunked, |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 # followed by some extra data. |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 ############################################################################### |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 use warnings; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use strict; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 use Test::More; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 use Socket qw/ CRLF /; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 use lib 'lib'; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 use Test::Nginx; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 ############################################################################### |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(1); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 daemon off; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 events { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 http { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 server { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 server_name localhost; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 proxy_buffer_size 128; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 proxy_buffers 4 128; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 location / { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 proxy_pass http://127.0.0.1:8081; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 proxy_read_timeout 1s; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 EOF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 $t->run_daemon(\&http_chunked_daemon); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 ############################################################################### |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 like(http_get('/'), qr/200 OK(?!.*zzz)/s, 'chunked with extra data'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 ############################################################################### |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 sub http_chunked_daemon { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 my $server = IO::Socket::INET->new( |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 Proto => 'tcp', |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 LocalAddr => '127.0.0.1:' . port(8081), |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 Listen => 5, |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 Reuse => 1 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 ) |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 or die "Can't create listening socket: $!\n"; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 local $SIG{PIPE} = 'IGNORE'; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 while (my $client = $server->accept()) { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 $client->autoflush(1); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 while (<$client>) { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 last if (/^\x0d?\x0a?$/); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 # return a large response start to allocate |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 # multiple buffers; stop at the buffer end |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 print $client "" |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 . "HTTP/1.1 200 OK" . CRLF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 . "Connection: close" . CRLF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 . "Transfer-Encoding: chunked" . CRLF . CRLF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 . "80" . CRLF . ("x" x 126) . CRLF . CRLF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 . "80" . CRLF . ("x" x 126) . CRLF . CRLF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 . "80" . CRLF . ("x" x 126) . CRLF . CRLF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 . "80" . CRLF . ("x" x 126) . CRLF . CRLF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 . "20" . CRLF . ("x" x 30) . CRLF . CRLF; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 select(undef, undef, undef, 0.3); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 # fill three full buffers here, so they are |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 # processed in order, regardless of the |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 # p->upstream_done flag set |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 print $client "" |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 . "75" . CRLF . ("y" x 115) . CRLF . CRLF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 . "0" . CRLF . CRLF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 . "75" . CRLF . ("z" x 115) . CRLF . CRLF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 . "0" . CRLF . CRLF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 . "75" . CRLF . ("z" x 115) . CRLF . CRLF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 . "0" . CRLF . CRLF; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 close $client; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
113 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
115 ############################################################################### |