Mercurial > hg > nginx-tests
comparison fastcgi_body2.t @ 433:4a045c74a77c
Tests: request body test with fastcgi_next_upstream.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 11 Jul 2014 17:00:06 +0400 |
parents | |
children | 67f41a61307c |
comparison
equal
deleted
inserted
replaced
432:c1269426585d | 433:4a045c74a77c |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 # (C) Sergey Kandaurov | |
5 # (C) Nginx, Inc. | |
6 | |
7 # Test for fastcgi backend with large request body, | |
8 # with fastcgi_next_upstream directive. | |
9 | |
10 ############################################################################### | |
11 | |
12 use warnings; | |
13 use strict; | |
14 | |
15 use Test::More; | |
16 | |
17 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
18 | |
19 use lib 'lib'; | |
20 use Test::Nginx; | |
21 | |
22 ############################################################################### | |
23 | |
24 select STDERR; $| = 1; | |
25 select STDOUT; $| = 1; | |
26 | |
27 eval { require FCGI; }; | |
28 plan(skip_all => 'FCGI not installed') if $@; | |
29 plan(skip_all => 'win32') if $^O eq 'MSWin32'; | |
30 | |
31 my $t = Test::Nginx->new()->has(qw/http fastcgi/)->plan(1) | |
32 ->write_file_expand('nginx.conf', <<'EOF'); | |
33 | |
34 %%TEST_GLOBALS%% | |
35 | |
36 daemon off; | |
37 | |
38 events { | |
39 } | |
40 | |
41 http { | |
42 %%TEST_GLOBALS_HTTP%% | |
43 | |
44 upstream u { | |
45 server 127.0.0.1:8081; | |
46 server 127.0.0.1:8082; | |
47 } | |
48 | |
49 server { | |
50 listen 127.0.0.1:8080; | |
51 server_name localhost; | |
52 | |
53 location / { | |
54 fastcgi_pass u; | |
55 fastcgi_param REQUEST_URI $request_uri; | |
56 fastcgi_param CONTENT_LENGTH $content_length; | |
57 # fastcgi_next_upstream error timeout; | |
58 fastcgi_read_timeout 1s; | |
59 } | |
60 } | |
61 } | |
62 | |
63 EOF | |
64 | |
65 $t->run_daemon(\&fastcgi_daemon, 8081); | |
66 $t->run_daemon(\&fastcgi_daemon, 8082); | |
67 $t->run(); | |
68 | |
69 $t->waitforsocket('127.0.0.1:8081'); | |
70 $t->waitforsocket('127.0.0.1:8082'); | |
71 | |
72 ############################################################################### | |
73 | |
74 TODO: { | |
75 local $TODO = 'not yet'; | |
76 | |
77 like(http_get_length('/', 'x' x 102400), qr/X-Length: 102400/, 'body length'); | |
78 | |
79 } | |
80 | |
81 ############################################################################### | |
82 | |
83 sub http_get_length { | |
84 my ($url, $body) = @_; | |
85 my $length = length $body; | |
86 return http(<<EOF); | |
87 GET $url HTTP/1.0 | |
88 Host: localhost | |
89 Content-Length: $length | |
90 | |
91 $body | |
92 EOF | |
93 } | |
94 | |
95 ############################################################################### | |
96 | |
97 sub fastcgi_daemon { | |
98 my ($port) = @_; | |
99 my $socket = FCGI::OpenSocket("127.0.0.1:$port", 5); | |
100 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, | |
101 $socket); | |
102 | |
103 my ($body, $len); | |
104 | |
105 while( $request->Accept() >= 0 ) { | |
106 read(STDIN, $body, $ENV{'CONTENT_LENGTH'}); | |
107 my $len = length $body; | |
108 | |
109 sleep 3 if $port == 8081; | |
110 | |
111 print <<EOF; | |
112 Location: http://127.0.0.1:8080/redirect | |
113 Content-Type: text/html | |
114 X-Length: $len | |
115 | |
116 EOF | |
117 } | |
118 | |
119 FCGI::CloseSocket($socket); | |
120 } | |
121 | |
122 ############################################################################### |