Mercurial > hg > nginx-tests
comparison fastcgi_body.t @ 240:462d89f5732a
Tests: request body and chunked transfer encoding tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 09 Nov 2012 07:46:37 +0400 |
parents | |
children | 8f280348d76f |
comparison
equal
deleted
inserted
replaced
239:5d178e27037c | 240:462d89f5732a |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Test for fastcgi backend with chunked request body. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
24 eval { require FCGI; }; | |
25 plan(skip_all => 'FCGI not installed') if $@; | |
26 plan(skip_all => 'win32') if $^O eq 'MSWin32'; | |
27 | |
28 my $t = Test::Nginx->new()->has(qw/http fastcgi/)->plan(5) | |
29 ->write_file_expand('nginx.conf', <<'EOF'); | |
30 | |
31 %%TEST_GLOBALS%% | |
32 | |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 http { | |
39 %%TEST_GLOBALS_HTTP%% | |
40 | |
41 server { | |
42 listen 127.0.0.1:8080; | |
43 server_name localhost; | |
44 | |
45 location / { | |
46 fastcgi_pass 127.0.0.1:8081; | |
47 fastcgi_param REQUEST_URI $request_uri; | |
48 fastcgi_param CONTENT_LENGTH $content_length; | |
49 } | |
50 } | |
51 } | |
52 | |
53 EOF | |
54 | |
55 $t->run_daemon(\&fastcgi_daemon); | |
56 $t->run(); | |
57 | |
58 ############################################################################### | |
59 | |
60 like(http_get('/'), qr/X-Body: /, 'fastcgi no body'); | |
61 | |
62 like(http_get_length('/', ''), qr/X-Body: /, 'fastcgi empty body'); | |
63 like(http_get_length('/', 'foobar'), qr/X-Body: foobar/, 'fastcgi body'); | |
64 | |
65 TODO: { | |
66 local $TODO = 'not yet'; | |
67 | |
68 like(http(<<EOF), qr/X-Body: foobar/, 'fastcgi chunked'); | |
69 GET / HTTP/1.1 | |
70 Host: localhost | |
71 Connection: close | |
72 Transfer-Encoding: chunked | |
73 | |
74 6 | |
75 foobar | |
76 0 | |
77 | |
78 EOF | |
79 | |
80 like(http(<<EOF), qr/X-Body: /, 'fastcgi empty chunked'); | |
81 GET / HTTP/1.1 | |
82 Host: localhost | |
83 Connection: close | |
84 Transfer-Encoding: chunked | |
85 | |
86 0 | |
87 | |
88 EOF | |
89 | |
90 } | |
91 | |
92 ############################################################################### | |
93 | |
94 sub http_get_length { | |
95 my ($url, $body) = @_; | |
96 my $length = length $body; | |
97 return http(<<EOF); | |
98 GET $url HTTP/1.1 | |
99 Host: localhost | |
100 Connection: close | |
101 Content-Length: $length | |
102 | |
103 $body | |
104 EOF | |
105 } | |
106 | |
107 ############################################################################### | |
108 | |
109 sub fastcgi_daemon { | |
110 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5); | |
111 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, | |
112 $socket); | |
113 | |
114 my $count; | |
115 my $body; | |
116 | |
117 while( $request->Accept() >= 0 ) { | |
118 $count++; | |
119 read(STDIN, $body, $ENV{'CONTENT_LENGTH'}); | |
120 | |
121 print <<EOF; | |
122 Location: http://127.0.0.1:8080/redirect | |
123 Content-Type: text/html | |
124 X-Body: $body | |
125 | |
126 SEE-THIS | |
127 $count | |
128 EOF | |
129 } | |
130 | |
131 FCGI::CloseSocket($socket); | |
132 } | |
133 | |
134 ############################################################################### |