Mercurial > hg > nginx-tests
comparison scgi_merge_params.t @ 182:23f81eb0a817
Tests: proxy_set_header/fastcgi_param/scgi_param tests.
These tests cover several problems, in particular ticket #45
(http://trac.nginx.org/nginx/ticket/45).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 08 Nov 2011 21:03:06 +0300 |
parents | |
children | 101b092b67e2 |
comparison
equal
deleted
inserted
replaced
181:e4024348b5ed | 182:23f81eb0a817 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for scgi_param inheritance. | |
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 SCGI; }; | |
25 plan(skip_all => 'SCGI not installed') if $@; | |
26 | |
27 my $t = Test::Nginx->new()->has(qw/http scgi cache/)->plan(9) | |
28 ->write_file_expand('nginx.conf', <<'EOF'); | |
29 | |
30 %%TEST_GLOBALS%% | |
31 | |
32 daemon off; | |
33 | |
34 events { | |
35 } | |
36 | |
37 http { | |
38 %%TEST_GLOBALS_HTTP%% | |
39 | |
40 scgi_cache_path %%TESTDIR%%/cache levels=1:2 | |
41 keys_zone=NAME:10m; | |
42 | |
43 scgi_param SCGI 1; | |
44 scgi_param HTTP_X_BLAH "blah"; | |
45 | |
46 server { | |
47 listen 127.0.0.1:8080; | |
48 server_name localhost; | |
49 | |
50 scgi_cache NAME; | |
51 | |
52 location / { | |
53 scgi_pass 127.0.0.1:8081; | |
54 } | |
55 | |
56 location /no/ { | |
57 scgi_pass 127.0.0.1:8081; | |
58 scgi_cache off; | |
59 } | |
60 | |
61 location /custom/ { | |
62 scgi_pass 127.0.0.1:8081; | |
63 scgi_param SCGI 1; | |
64 scgi_param HTTP_X_BLAH "custom"; | |
65 } | |
66 } | |
67 } | |
68 | |
69 EOF | |
70 | |
71 $t->run_daemon(\&scgi_daemon); | |
72 $t->run(); | |
73 | |
74 ############################################################################### | |
75 | |
76 like(http_get_ims('/'), qr/ims=;/, | |
77 'if-modified-since cleared with cache'); | |
78 | |
79 TODO: { | |
80 local $TODO = 'not yet'; | |
81 | |
82 like(http_get_ims('/'), qr/iums=;/, | |
83 'if-unmodified-since cleared with cache'); | |
84 | |
85 } | |
86 | |
87 like(http_get_ims('/'), qr/blah=blah;/, | |
88 'custom params with cache'); | |
89 | |
90 TODO: { | |
91 local $TODO = 'not yet'; | |
92 | |
93 like(http_get_ims('/no/'), qr/ims=blah;/, | |
94 'if-modified-since preserved without cache'); | |
95 | |
96 } | |
97 | |
98 like(http_get_ims('/no/'), qr/iums=blah;/, | |
99 'if-unmodified-since preserved without cache'); | |
100 like(http_get_ims('/'), qr/blah=blah;/, | |
101 'custom params without cache'); | |
102 | |
103 like(http_get_ims('/custom/'), qr/ims=;/, | |
104 'if-modified-since cleared with cache custom'); | |
105 | |
106 TODO: { | |
107 local $TODO = 'not yet'; | |
108 | |
109 like(http_get_ims('/custom/'), qr/iums=;/, | |
110 'if-unmodified-since cleared with cache custom'); | |
111 } | |
112 | |
113 like(http_get_ims('/custom/'), qr/blah=custom;/, | |
114 'custom params with cache custom'); | |
115 | |
116 ############################################################################### | |
117 | |
118 sub http_get_ims { | |
119 my ($url) = @_; | |
120 return http(<<EOF); | |
121 GET $url HTTP/1.0 | |
122 Host: localhost | |
123 Connection: close | |
124 If-Modified-Since: blah | |
125 If-Unmodified-Since: blah | |
126 | |
127 EOF | |
128 } | |
129 | |
130 ############################################################################### | |
131 | |
132 sub scgi_daemon { | |
133 my $server = IO::Socket::INET->new( | |
134 Proto => 'tcp', | |
135 LocalHost => '127.0.0.1:8081', | |
136 Listen => 5, | |
137 Reuse => 1 | |
138 ) | |
139 or die "Can't create listening socket: $!\n"; | |
140 | |
141 my $scgi = SCGI->new($server, blocking => 1); | |
142 my $count = 0; | |
143 | |
144 while (my $request = $scgi->accept()) { | |
145 $count++; | |
146 $request->read_env(); | |
147 | |
148 my $ims = $request->env->{HTTP_IF_MODIFIED_SINCE} || ''; | |
149 my $iums = $request->env->{HTTP_IF_UNMODIFIED_SINCE} || ''; | |
150 my $blah = $request->env->{HTTP_X_BLAH} || ''; | |
151 | |
152 $request->connection()->print(<<EOF); | |
153 Location: http://127.0.0.1:8080/redirect | |
154 Content-Type: text/html | |
155 | |
156 ims=$ims;iums=$iums;blah=$blah; | |
157 EOF | |
158 } | |
159 } | |
160 | |
161 ############################################################################### |