Mercurial > hg > nginx-tests
comparison rewrite_set.t @ 448:29ee0d2b0746
Tests: tests for rewrite "set" directive.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 12 Aug 2014 15:37:27 +0400 |
parents | |
children | a65cb9330c91 |
comparison
equal
deleted
inserted
replaced
447:183f21bbe3d6 | 448:29ee0d2b0746 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for rewrite set. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http rewrite ssi/)->plan(4); | |
26 | |
27 $t->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 server { | |
40 listen 127.0.0.1:8080; | |
41 server_name localhost; | |
42 | |
43 ssi on; | |
44 | |
45 location /t1 { | |
46 set $http_foo "set_foo"; | |
47 return 200 'X<!--#echo var="http_foo" -->X'; | |
48 } | |
49 | |
50 location /t2 { | |
51 return 200 'X<!--#echo var="http_bar" -->X'; | |
52 } | |
53 | |
54 location /t3 { | |
55 return 200 'X<!--#echo var="http_baz" -->X'; | |
56 } | |
57 | |
58 location /t4 { | |
59 set $http_connection "bar"; | |
60 return 200 "X${http_connection}X\n"; | |
61 } | |
62 | |
63 # set in other context | |
64 location /other { | |
65 set $http_bar "set_bar"; | |
66 } | |
67 } | |
68 } | |
69 | |
70 EOF | |
71 | |
72 $t->run(); | |
73 | |
74 ############################################################################### | |
75 | |
76 # prefixed variables | |
77 | |
78 TODO: { | |
79 local $TODO = 'not yet'; | |
80 | |
81 SKIP: { | |
82 skip 'leaves coredump', 2 unless $ENV{TEST_NGINX_UNSAFE}; | |
83 | |
84 like(http_get_extra('/t1.html', 'Foo: http_foo'), qr/Xset_fooX/, | |
85 'set in this context'); | |
86 like(http_get_extra('/t2.html', 'Bar: http_bar'), qr/Xhttp_barX/, | |
87 'set in other context'); | |
88 | |
89 } | |
90 } | |
91 | |
92 like(http_get_extra('/t3.html', 'Baz: http_baz'), qr/Xhttp_bazX/, 'not set'); | |
93 | |
94 like(http_get('/t4.html'), qr/XbarX/, 'set get in return'); | |
95 | |
96 ############################################################################### | |
97 | |
98 sub http_get_extra { | |
99 my ($uri, $extra) = @_; | |
100 return http(<<EOF); | |
101 GET $uri HTTP/1.0 | |
102 $extra | |
103 | |
104 EOF | |
105 } | |
106 | |
107 ############################################################################### |