Mercurial > hg > nginx-tests
annotate fastcgi_request_buffering.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 42d9fd20eeb6 |
children |
rev | line source |
---|---|
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Sergey Kandaurov |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 # (C) Nginx, Inc. |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 # Tests for unbuffered request body with fastcgi backend. |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 ############################################################################### |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use warnings; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 use strict; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 use Test::More; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use Socket qw/ CRLF /; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 eval { require FCGI; }; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 plan(skip_all => 'FCGI not installed') if $@; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
545
diff
changeset
|
31 my $t = Test::Nginx->new()->has(qw/http fastcgi rewrite/)->plan(15); |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 $t->write_file_expand('nginx.conf', <<'EOF'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 %%TEST_GLOBALS%% |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 daemon off; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 events { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 http { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 %%TEST_GLOBALS_HTTP%% |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
46 listen 127.0.0.1:8080; |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 server_name localhost; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 client_header_buffer_size 1k; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 fastcgi_request_buffering off; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 fastcgi_param REQUEST_URI $request_uri; |
545
dbf8fb0f3d30
Tests: fixed unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
542
diff
changeset
|
52 fastcgi_param CONTENT_LENGTH $content_length; |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 location / { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 client_body_buffer_size 2k; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
56 fastcgi_pass 127.0.0.1:8081; |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 location /single { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 client_body_in_single_buffer on; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
60 fastcgi_pass 127.0.0.1:8081; |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 location /preread { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
63 fastcgi_pass 127.0.0.1:8082; |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 location /error_page { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
66 fastcgi_pass 127.0.0.1:8081; |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 error_page 404 /404; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 fastcgi_intercept_errors on; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 location /404 { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 return 200 "$request_body\n"; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 EOF |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 $t->run_daemon(\&fastcgi_daemon); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
79 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 ############################################################################### |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
545
dbf8fb0f3d30
Tests: fixed unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
542
diff
changeset
|
83 like(http_get('/'), qr/X-Body: \x0d\x0a?/ms, 'no body'); |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 like(http_get_body('/', '0123456789'), |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 qr/X-Body: 0123456789\x0d?$/ms, 'body'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 like(http_get_body('/', '0123456789' x 128), |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 qr/X-Body: (0123456789){128}\x0d?$/ms, 'body in two buffers'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 like(http_get_body('/single', '0123456789' x 128), |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 qr/X-Body: (0123456789){128}\x0d?$/ms, 'body in single buffer'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 like(http_get_body('/error_page', '0123456789'), |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 qr/^0123456789$/m, 'body in error page'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 # pipelined requests |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 like(http_get_body('/', '0123456789', '0123456789' x 128, '0123456789' x 512, |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 'foobar'), qr/X-Body: foobar\x0d?$/ms, 'body pipelined'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 like(http_get_body('/', '0123456789' x 128, '0123456789' x 512, '0123456789', |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 'foobar'), qr/X-Body: foobar\x0d?$/ms, 'body pipelined 2'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 # interactive tests |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
106 my $s = get_body('/preread', port(8082), 10); |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 ok($s, 'no preread'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 SKIP: { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 skip 'no preread failed', 3 unless $s; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 is($s->{upload}('01234'), '01234', 'no preread - body part'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 is($s->{upload}('56789'), '56789', 'no preread - body part 2'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 like($s->{http_end}(), qr/200 OK/, 'no preread - response'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
119 $s = get_body('/preread', port(8082), 10, '01234'); |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 ok($s, 'preread'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 SKIP: { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 skip 'preread failed', 3 unless $s; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 is($s->{preread}, '01234', 'preread - preread'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 is($s->{upload}('56789'), '56789', 'preread - body'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 like($s->{http_end}(), qr/200 OK/, 'preread - response'); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 ############################################################################### |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 sub http_get_body { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 my $uri = shift; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 my $last = pop; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 return http( join '', (map { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 my $body = $_; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 "GET $uri HTTP/1.1" . CRLF |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 . "Host: localhost" . CRLF |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 . "Content-Length: " . (length $body) . CRLF . CRLF |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 . $body |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 } @_), |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 "GET $uri HTTP/1.1" . CRLF |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 . "Host: localhost" . CRLF |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 . "Connection: close" . CRLF |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 . "Content-Length: " . (length $last) . CRLF . CRLF |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 . $last |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 ); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 # Simple FastCGI responder implementation. |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 # http://www.fastcgi.com/devkit/doc/fcgi-spec.html |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 sub fastcgi_read_record($) { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 my ($buf) = @_; |
925
6bb1f2ccd386
Tests: removed unused variables.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
837
diff
changeset
|
158 my $h; |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 return undef unless length $$buf; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 @{$h}{qw/ version type id clen plen /} = unpack("CCnnC", $$buf); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 $h->{content} = substr $$buf, 8, $h->{clen}; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 $h->{padding} = substr $$buf, 8 + $h->{clen}, $h->{plen}; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 $$buf = substr $$buf, 8 + $h->{clen} + $h->{plen}; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 return $h; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 sub fastcgi_respond($$$$) { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 my ($socket, $version, $id, $body) = @_; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 # stdout |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 $socket->write(pack("CCnnCx", $version, 6, $id, length($body), 8)); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 $socket->write($body); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 select(undef, undef, undef, 0.1); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 $socket->write(pack("xxxxxxxx")); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 select(undef, undef, undef, 0.1); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 # write some text to stdout and stderr split over multiple network |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 # packets to test if we correctly set pipe length in various places |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 my $tt = "test text, just for test"; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 $socket->write(pack("CCnnCx", $version, 6, $id, |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 length($tt . $tt), 0) . $tt); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 select(undef, undef, undef, 0.1); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 $socket->write($tt . pack("CC", $version, 7)); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 select(undef, undef, undef, 0.1); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 $socket->write(pack("nnCx", $id, length($tt), 0)); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 select(undef, undef, undef, 0.1); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 $socket->write($tt); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 select(undef, undef, undef, 0.1); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 # close stdout |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 $socket->write(pack("CCnnCx", $version, 6, $id, 0, 0)); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 select(undef, undef, undef, 0.1); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 # end request |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 $socket->write(pack("CCnnCx", $version, 3, $id, 8, 0)); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 select(undef, undef, undef, 0.1); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 $socket->write(pack("NCxxx", 0, 0)); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 sub get_body { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 my ($url, $port, $length, $body) = @_; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 my ($server, $client, $s); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 my ($version, $id); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 $server = IO::Socket::INET->new( |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
214 Proto => 'tcp', |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
215 LocalHost => '127.0.0.1', |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
216 LocalPort => $port, |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
217 Listen => 5, |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
218 Reuse => 1 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
219 ) |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
220 or die "Can't create listening socket: $!\n"; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
221 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
222 my $r = <<EOF; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
223 GET $url HTTP/1.1 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
224 Host: localhost |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
225 Connection: close |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
226 Content-Length: $length |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
227 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
228 EOF |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
229 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
230 if (defined $body) { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
231 $r .= $body; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
232 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
233 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
234 $s = http($r, start => 1); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
235 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
236 eval { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
237 local $SIG{ALRM} = sub { die "timeout\n" }; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
238 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
239 alarm(5); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
240 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
241 $client = $server->accept(); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
242 |
837
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
243 log2c("(new connection $client)"); |
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
244 |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
245 alarm(0); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
246 }; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
247 alarm(0); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
248 if ($@) { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
249 log_in("died: $@"); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
250 return undef; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
251 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
252 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
253 $client->sysread(my $buf, 1024); |
837
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
254 log2i($buf); |
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
255 |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
256 $body = ''; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
257 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
258 while (my $h = fastcgi_read_record(\$buf)) { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
259 $version = $h->{version}; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
260 $id = $h->{id}; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
261 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
262 # skip everything unless stdin |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
263 next if $h->{type} != 5; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
264 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
265 $body .= $h->{content}; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
266 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
267 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
268 my $f = { preread => $body }; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
269 $f->{upload} = sub { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
270 my $buf = shift; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
271 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
272 eval { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
273 local $SIG{ALRM} = sub { die "timeout\n" }; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
274 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
275 alarm(5); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
276 |
837
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
277 log_out($buf); |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
278 $s->write($buf); |
837
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
279 |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
280 $client->sysread($buf, 1024); |
837
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
281 log2i($buf); |
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
282 |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
283 $body = ''; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
284 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
285 while (my $h = fastcgi_read_record(\$buf)) { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
286 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
287 # skip everything unless stdin |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
288 next if $h->{type} != 5; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
289 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
290 $body .= $h->{content}; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
291 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
292 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
293 alarm(0); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
294 }; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
295 alarm(0); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
296 if ($@) { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
297 log_in("died: $@"); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
298 return undef; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
299 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
300 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
301 return $body; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
302 }; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
303 $f->{http_end} = sub { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
304 my $buf = ''; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
305 |
1167
1e79a9613813
Tests: handled SIGPIPE in fastcgi tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
306 eval { |
1e79a9613813
Tests: handled SIGPIPE in fastcgi tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
307 local $SIG{ALRM} = sub { die "timeout\n" }; |
1e79a9613813
Tests: handled SIGPIPE in fastcgi tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
308 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
1e79a9613813
Tests: handled SIGPIPE in fastcgi tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
309 alarm(5); |
1e79a9613813
Tests: handled SIGPIPE in fastcgi tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
310 |
1e79a9613813
Tests: handled SIGPIPE in fastcgi tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
311 fastcgi_respond($client, $version, $id, <<EOF); |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
312 Status: 200 OK |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
313 Connection: close |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
314 X-Port: $port |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
315 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
316 OK |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
317 EOF |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
318 |
1167
1e79a9613813
Tests: handled SIGPIPE in fastcgi tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
319 $client->close; |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
320 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
321 $s->sysread($buf, 1024); |
837
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
322 log_in($buf); |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
323 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
324 alarm(0); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
325 }; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
326 alarm(0); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
327 if ($@) { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
328 log_in("died: $@"); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
329 return undef; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
330 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
331 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
332 return $buf; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
333 }; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
334 return $f; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
335 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
336 |
837
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
337 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
338 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
339 sub log2c { Test::Nginx::log_core('||', @_); } |
68a6678abae2
Tests: improved logging for unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
340 |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
341 ############################################################################### |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
342 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
343 sub fastcgi_daemon { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
344 my $socket = FCGI::OpenSocket('127.0.0.1:' . port(8081), 5); |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
345 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
346 $socket); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
347 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
348 my $count; |
545
dbf8fb0f3d30
Tests: fixed unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
542
diff
changeset
|
349 my $body; |
dbf8fb0f3d30
Tests: fixed unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
542
diff
changeset
|
350 |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
351 while( $request->Accept() >= 0 ) { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
352 $count++; |
1791
42d9fd20eeb6
Tests: avoid uninitialized warnings in fastcgi tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1167
diff
changeset
|
353 read(STDIN, $body, $ENV{'CONTENT_LENGTH'} || 0); |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
354 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
355 if ($ENV{REQUEST_URI} eq '/error_page') { |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
356 print "Status: 404 Not Found" . CRLF . CRLF; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
357 next; |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
358 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
359 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
360 print <<EOF; |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
361 Location: http://localhost/redirect |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
362 Content-Type: text/html |
545
dbf8fb0f3d30
Tests: fixed unbuffered request body tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
542
diff
changeset
|
363 X-Body: $body |
542
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
364 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
365 SEE-THIS |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
366 $count |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
367 EOF |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
368 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
369 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
370 FCGI::CloseSocket($socket); |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
371 } |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
372 |
e7e3ced702f5
Tests: unbuffered request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
373 ############################################################################### |