comparison proxy_chunked_extra.t @ 1581:463d6863d360

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