comparison fastcgi_split.t @ 380:74a015aad352

Tests: split headers and fastcgi_next_upstream test.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 17 Mar 2014 16:02:19 +0400
parents
children 847ea345becb
comparison
equal deleted inserted replaced
379:f42de3a9fd74 380:74a015aad352
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Test for fastcgi backend.
6 # Incorrect split headers handling after switching to next server,
7 # as reported by Lucas Molas.
8
9 ###############################################################################
10
11 use warnings;
12 use strict;
13
14 use Test::More;
15 use Socket qw/ CR LF CRLF /;
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_next_upstream invalid_header;
57 }
58 }
59 }
60
61 EOF
62
63 $t->run_daemon(\&fastcgi_daemon, 8081);
64 $t->run_daemon(\&fastcgi_daemon, 8082);
65
66 $t->run();
67
68 $t->waitforsocket('127.0.0.1:8081');
69 $t->waitforsocket('127.0.0.1:8082');
70
71 ###############################################################################
72
73 TODO: {
74 local $TODO = 'not yet' unless $t->has_version('1.5.12');
75
76 like(http_get('/'), qr/^Good: header/ms, 'fastcgi next upstream');
77
78 }
79
80 ###############################################################################
81
82 sub fastcgi_daemon {
83 my ($port) = @_;
84 my $socket = FCGI::OpenSocket("127.0.0.1:$port", 5);
85 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
86 $socket);
87
88 my $count;
89 while( $request->Accept() >= 0 ) {
90 $count++;
91
92 if ($port == 8081) {
93 print 'BAD';
94 }
95 if ($port == 8082) {
96 print 'Good: header' . CRLF . CRLF;
97 }
98 }
99
100 FCGI::CloseSocket($socket);
101 }
102
103 ###############################################################################