Mercurial > hg > nginx-tests
comparison http_absolute_redirect.t @ 1103:71bba21ea3ed
Tests: absolute_redirect and related tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 29 Dec 2016 18:24:53 +0300 |
parents | |
children | ccf134a800ae |
comparison
equal
deleted
inserted
replaced
1102:89d7d4d1be40 | 1103:71bba21ea3ed |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for absolute_redirect directive. | |
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 proxy rewrite/) | |
26 ->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 http { | |
36 %%TEST_GLOBALS_HTTP%% | |
37 | |
38 absolute_redirect off; | |
39 | |
40 server { | |
41 listen 127.0.0.1:8080; | |
42 server_name on; | |
43 | |
44 absolute_redirect on; | |
45 | |
46 location / { } | |
47 | |
48 location /auto/ { | |
49 proxy_pass http://127.0.0.1:8080; | |
50 } | |
51 | |
52 location /return301 { | |
53 return 301 /redirect; | |
54 } | |
55 } | |
56 | |
57 server { | |
58 listen 127.0.0.1:8080; | |
59 server_name off; | |
60 | |
61 location / { } | |
62 | |
63 location /auto/ { | |
64 proxy_pass http://127.0.0.1:8080; | |
65 } | |
66 | |
67 location /return301 { | |
68 return 301 /redirect; | |
69 } | |
70 } | |
71 } | |
72 | |
73 EOF | |
74 | |
75 mkdir($t->testdir() . '/dir'); | |
76 | |
77 $t->try_run('no absolute_redirect')->plan(6); | |
78 | |
79 ############################################################################### | |
80 | |
81 my $p = port(8080); | |
82 | |
83 like(get('on', '/dir'), qr!Location: http://on:$p/dir/!, 'directory'); | |
84 like(get('on', '/auto'), qr!Location: http://on:$p/auto/!, 'auto'); | |
85 like(get('on', '/return301'), qr!Location: http://on:$p/redirect!, 'return'); | |
86 | |
87 like(get('off', '/dir'), qr!Location: /dir/!, 'off directory'); | |
88 like(get('off', '/auto'), qr!Location: /auto/!, 'off auto'); | |
89 like(get('off', '/return301'), qr!Location: /redirect!, 'off return'); | |
90 | |
91 ############################################################################### | |
92 | |
93 sub get { | |
94 my ($host, $uri) = @_; | |
95 http(<<EOF); | |
96 GET $uri HTTP/1.0 | |
97 Host: $host | |
98 | |
99 EOF | |
100 } | |
101 | |
102 ############################################################################### |