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