Mercurial > hg > nginx-tests
annotate fastcgi_body.t @ 945:d73bef563aea
Tests: speed up HTTP/2 tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 15 Jun 2016 13:27:56 +0300 |
parents | 6bb1f2ccd386 |
children | e9064d691790 |
rev | line source |
---|---|
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for fastcgi backend with chunked request body. |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http fastcgi/)->plan(5) |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ->write_file_expand('nginx.conf', <<'EOF'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 %%TEST_GLOBALS%% |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
242
diff
changeset
|
29 daemon off; |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 events { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 http { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 %%TEST_GLOBALS_HTTP%% |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 server { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 listen 127.0.0.1:8080; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 server_name localhost; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 location / { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 fastcgi_pass 127.0.0.1:8081; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 fastcgi_param REQUEST_URI $request_uri; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 fastcgi_param CONTENT_LENGTH $content_length; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 EOF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 $t->run_daemon(\&fastcgi_daemon); |
295
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
52 $t->run()->waitforsocket('127.0.0.1:8081'); |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 ############################################################################### |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 |
895
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
56 like(http_get('/'), qr/X-Body: _eos\x0d?$/ms, 'fastcgi no body'); |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 |
895
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
58 like(http_get_length('/', ''), qr/X-Body: _eos\x0d?$/ms, 'fastcgi empty body'); |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
59 like(http_get_length('/', 'foobar'), qr/X-Body: foobar_eos\x0d?$/ms, |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
60 'fastcgi body'); |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 |
895
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
62 TODO: { |
898
3f453670bfac
Tests: fastcgi TODOs for chunked request body adjusted.
Sergey Kandaurov <pluknet@nginx.com>
parents:
895
diff
changeset
|
63 local $TODO = 'not yet' unless $t->has_version('1.9.15'); |
895
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
64 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
65 like(http(<<EOF), qr/X-Body: foobar_eos\x0d?$/ms, 'fastcgi chunked'); |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 GET / HTTP/1.1 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 Host: localhost |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 Connection: close |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 Transfer-Encoding: chunked |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 6 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 foobar |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 0 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 EOF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
895
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
77 like(http(<<EOF), qr/X-Body: _eos\x0d?$/ms, 'fastcgi empty chunked'); |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 GET / HTTP/1.1 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 Host: localhost |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 Connection: close |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 Transfer-Encoding: chunked |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 0 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 EOF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 |
895
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
87 } |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
88 |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 ############################################################################### |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 sub http_get_length { |
589
a9569f57da98
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
317
diff
changeset
|
92 my ($url, $body) = @_; |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 my $length = length $body; |
589
a9569f57da98
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
317
diff
changeset
|
94 return http(<<EOF); |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 GET $url HTTP/1.1 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 Host: localhost |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 Connection: close |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 Content-Length: $length |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 $body |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 EOF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 ############################################################################### |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 |
895
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
106 # Simple FastCGI responder implementation. |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
107 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
108 # http://www.fastcgi.com/devkit/doc/fcgi-spec.html |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
109 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
110 sub fastcgi_read_record($) { |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
111 my ($buf) = @_; |
925
6bb1f2ccd386
Tests: removed unused variables.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
898
diff
changeset
|
112 my $h; |
895
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
113 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
114 return undef unless length $$buf; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
115 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
116 @{$h}{qw/ version type id clen plen /} = unpack("CCnnC", $$buf); |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
117 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
118 $h->{content} = substr $$buf, 8, $h->{clen}; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
119 $h->{padding} = substr $$buf, 8 + $h->{clen}, $h->{plen}; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
120 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
121 $$buf = substr $$buf, 8 + $h->{clen} + $h->{plen}; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
122 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
123 return $h; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
124 } |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
125 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
126 sub fastcgi_respond($$$$) { |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
127 my ($socket, $version, $id, $body) = @_; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
128 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
129 # stdout |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
130 $socket->write(pack("CCnnCx", $version, 6, $id, length($body), 0)); |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
131 $socket->write($body); |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
132 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
133 # close stdout |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
134 $socket->write(pack("CCnnCx", $version, 6, $id, 0, 0)); |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
135 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
136 # end request |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
137 $socket->write(pack("CCnnCx", $version, 3, $id, 8, 0)); |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
138 $socket->write(pack("NCxxx", 0, 0)); |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
139 } |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
140 |
895
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
141 sub fastcgi_daemon { |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
142 my $server = IO::Socket::INET->new( |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
143 Proto => 'tcp', |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
144 LocalAddr => '127.0.0.1:8081', |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
145 Listen => 5, |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
146 Reuse => 1 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
147 ) |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
148 or die "Can't create listening socket: $!\n"; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
149 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
150 local $SIG{PIPE} = 'IGNORE'; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
151 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
152 while (my $client = $server->accept()) { |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
153 $client->autoflush(1); |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
154 Test::Nginx::log_core('||', "fastcgi connection"); |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
155 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
156 $client->sysread(my $buf, 1024) or next; |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
157 |
895
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
158 my ($version, $id); |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
159 my $body = ''; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
160 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
161 while (my $h = fastcgi_read_record(\$buf)) { |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
162 $version = $h->{version}; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
163 $id = $h->{id}; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
164 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
165 Test::Nginx::log_core('||', "fastcgi record: " |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
166 . " $h->{version}, $h->{type}, $h->{id}, " |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
167 . "'$h->{content}'"); |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
168 |
895
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
169 if ($h->{type} == 5) { |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
170 $body .= $h->{content} if $h->{clen} > 0; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
171 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
172 # count stdin end-of-stream |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
173 $body .= '_eos' if $h->{clen} == 0; |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
174 } |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
175 } |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
176 |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
177 # respond |
894e142ebdf8
Tests: TODO fastcgi request body end-of-stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
589
diff
changeset
|
178 fastcgi_respond($client, $version, $id, <<EOF); |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
179 Location: http://127.0.0.1:8080/redirect |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
180 Content-Type: text/html |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
181 X-Body: $body |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
182 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
183 SEE-THIS |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
184 EOF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
185 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
186 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
187 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
188 ############################################################################### |