comparison fastcgi_header_params.t @ 153:26cf61c5ac35

Tests: fastcgi header params test. Only run with TEST_NGINX_UNSAFE set as unpatched nginx dumps core on it.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 14 Jun 2011 03:35:47 +0400
parents
children c0ae29632905
comparison
equal deleted inserted replaced
152:c9be30f65be7 153:26cf61c5ac35
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Test for fastcgi header params.
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
27 my $t = Test::Nginx->new()->has(qw/http fastcgi/)->plan(1)
28 ->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 master_process off;
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 HTTP_X_BLAH "blah";
48 }
49 }
50 }
51
52 EOF
53
54 $t->run_daemon(\&fastcgi_daemon);
55 $t->run();
56
57 ###############################################################################
58
59 SKIP: {
60 skip 'unsafe', 1 unless $ENV{TEST_NGINX_UNSAFE};
61
62 local $TODO = 'not yet';
63
64 like(http_get_headers('/'), qr/SEE-THIS/,
65 'fastcgi request with many ignored headers');
66
67 }
68
69 ###############################################################################
70
71 sub http_get_headers {
72 my ($url, %extra) = @_;
73 return http(<<EOF, %extra);
74 GET $url HTTP/1.0
75 Host: localhost
76 X-Blah: ignored header
77 X-Blah: ignored header
78 X-Blah: ignored header
79 X-Blah: ignored header
80 X-Blah: ignored header
81 X-Blah: ignored header
82 X-Blah: ignored header
83 X-Blah: ignored header
84 X-Blah: ignored header
85 X-Blah: ignored header
86 X-Blah: ignored header
87 X-Blah: ignored header
88 X-Blah: ignored header
89 X-Blah: ignored header
90 X-Blah: ignored header
91 X-Blah: ignored header
92 X-Blah: ignored header
93 X-Blah: ignored header
94 X-Blah: ignored header
95
96 EOF
97 }
98
99 ###############################################################################
100
101 sub fastcgi_daemon {
102 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5);
103 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
104 $socket);
105
106 my $count;
107 while( $request->Accept() >= 0 ) {
108 $count++;
109
110 print <<EOF;
111 Location: http://127.0.0.1:8080/redirect
112 Content-Type: text/html
113
114 SEE-THIS
115 $count
116 EOF
117 }
118
119 FCGI::CloseSocket($socket);
120 }
121
122 ###############################################################################