Mercurial > hg > nginx-tests
comparison fastcgi_merge_params2.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 fastcgi_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 FCGI; }; | |
25 plan(skip_all => 'FCGI not installed') if $@; | |
26 | |
27 | |
28 my $t = Test::Nginx->new()->has(qw/http fastcgi cache/)->plan(4) | |
29 ->write_file_expand('nginx.conf', <<'EOF'); | |
30 | |
31 %%TEST_GLOBALS%% | |
32 | |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 http { | |
39 %%TEST_GLOBALS_HTTP%% | |
40 | |
41 fastcgi_cache_path %%TESTDIR%%/cache levels=1:2 | |
42 keys_zone=NAME:10m; | |
43 | |
44 # no fastcgi_param at all, cache switched on at server level | |
45 | |
46 server { | |
47 listen 127.0.0.1:8080; | |
48 server_name localhost; | |
49 | |
50 fastcgi_cache NAME; | |
51 | |
52 location / { | |
53 fastcgi_pass 127.0.0.1:8081; | |
54 } | |
55 | |
56 location /no/ { | |
57 fastcgi_pass 127.0.0.1:8081; | |
58 fastcgi_cache off; | |
59 } | |
60 } | |
61 } | |
62 | |
63 EOF | |
64 | |
65 $t->run_daemon(\&fastcgi_daemon); | |
66 $t->run(); | |
67 | |
68 ############################################################################### | |
69 | |
70 TODO: { | |
71 local $TODO = 'not yet'; | |
72 | |
73 like(http_get_ims('/'), qr/ims=;/, | |
74 'if-modified-since cleared with cache'); | |
75 like(http_get_ims('/'), qr/iums=;/, | |
76 'if-unmodified-since cleared with cache'); | |
77 | |
78 } | |
79 | |
80 like(http_get_ims('/no/'), qr/ims=blah;/, | |
81 'if-modified-since preserved without cache'); | |
82 like(http_get_ims('/no/'), qr/iums=blah;/, | |
83 'if-unmodified-since preserved without cache'); | |
84 | |
85 ############################################################################### | |
86 | |
87 sub http_get_ims { | |
88 my ($url) = @_; | |
89 return http(<<EOF); | |
90 GET $url HTTP/1.0 | |
91 Host: localhost | |
92 Connection: close | |
93 If-Modified-Since: blah | |
94 If-Unmodified-Since: blah | |
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 my $ims = $ENV{HTTP_IF_MODIFIED_SINCE}; | |
111 my $iums = $ENV{HTTP_IF_UNMODIFIED_SINCE}; | |
112 my $blah = $ENV{HTTP_X_BLAH}; | |
113 | |
114 print <<EOF; | |
115 Location: http://127.0.0.1:8080/redirect | |
116 Content-Type: text/html | |
117 | |
118 ims=$ims;iums=$iums;blah=$blah; | |
119 EOF | |
120 } | |
121 | |
122 FCGI::CloseSocket($socket); | |
123 } | |
124 | |
125 ############################################################################### |