Mercurial > hg > nginx-tests
annotate fastcgi_body.t @ 488:8474d27c9147
Tests: adjusted SPDY TODOs, fix committed.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 29 Oct 2014 15:31:27 +0300 |
parents | a9621dbbd0d4 |
children | a9569f57da98 |
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 eval { require FCGI; }; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 plan(skip_all => 'FCGI not installed') if $@; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 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
|
29 ->write_file_expand('nginx.conf', <<'EOF'); |
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 %%TEST_GLOBALS%% |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
242
diff
changeset
|
33 daemon off; |
240
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 events { |
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 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 http { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
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 server { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 server_name localhost; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 location / { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 fastcgi_pass 127.0.0.1:8081; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 fastcgi_param REQUEST_URI $request_uri; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 fastcgi_param CONTENT_LENGTH $content_length; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 } |
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 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 EOF |
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 $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
|
56 $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
|
57 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 ############################################################################### |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 like(http_get('/'), qr/X-Body: /, 'fastcgi no body'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 like(http_get_length('/', ''), qr/X-Body: /, 'fastcgi empty body'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 like(http_get_length('/', 'foobar'), qr/X-Body: foobar/, 'fastcgi body'); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 like(http(<<EOF), qr/X-Body: foobar/, 'fastcgi chunked'); |
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 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 like(http(<<EOF), qr/X-Body: /, 'fastcgi empty chunked'); |
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 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 ############################################################################### |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 sub http_get_length { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 my ($url, $body) = @_; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 my $length = length $body; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 return http(<<EOF); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 GET $url HTTP/1.1 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 Host: localhost |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 Connection: close |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 Content-Length: $length |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 $body |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 EOF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 |
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 sub fastcgi_daemon { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 $socket); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 my $count; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 my $body; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 while( $request->Accept() >= 0 ) { |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
113 $count++; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 read(STDIN, $body, $ENV{'CONTENT_LENGTH'}); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
115 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
116 print <<EOF; |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
117 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
|
118 Content-Type: text/html |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
119 X-Body: $body |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
120 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
121 SEE-THIS |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
122 $count |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
123 EOF |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
124 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
125 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
126 FCGI::CloseSocket($socket); |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
127 } |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
128 |
462d89f5732a
Tests: request body and chunked transfer encoding tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
129 ############################################################################### |