Mercurial > hg > nginx-tests
annotate http_server_name.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
4 # (C) Andrey Zelenkov |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
5 # (C) Nginx, Inc. |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 # Tests for server_name selection. |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 ############################################################################### |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 use warnings; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use strict; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 use Test::More; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
16 use Socket qw/ CRLF /; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
17 |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 BEGIN { use FindBin; chdir($FindBin::Bin); } |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 use lib 'lib'; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 use Test::Nginx; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 ############################################################################### |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
223
f9325406df0b
Tests: skip tests not appropriate for win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
210
diff
changeset
|
28 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
f9325406df0b
Tests: skip tests not appropriate for win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
210
diff
changeset
|
29 |
689
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
30 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(20) |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 ->write_file_expand('nginx.conf', <<'EOF'); |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 %%TEST_GLOBALS%% |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
223
diff
changeset
|
35 daemon off; |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 events { |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 } |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 http { |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 %%TEST_GLOBALS_HTTP%% |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 |
210
a5f810eb87a2
Tests: explicitly set server names hash bucket size to 64.
Maxim Dounin <mdounin@mdounin.ru>
parents:
171
diff
changeset
|
43 server_names_hash_bucket_size 64; |
a5f810eb87a2
Tests: explicitly set server names hash bucket size to 64.
Maxim Dounin <mdounin@mdounin.ru>
parents:
171
diff
changeset
|
44 |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
46 listen 127.0.0.1:8080; |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 server_name localhost; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 location / { |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 add_header X-Server $server_name; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 } |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
55 listen 127.0.0.1:8080; |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
56 server_name ""; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
57 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
58 location / { |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
59 add_header X-Server $server_name; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
60 } |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
61 } |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
62 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
63 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
64 listen 127.0.0.1:8080; |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 server_name www.example.com; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 location / { |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 add_header X-Server $server_name; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 } |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 } |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
73 listen 127.0.0.1:8080; |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 server_name ~^EXAMPLE\.COM$; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 location / { |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 add_header X-Server $server_name; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 } |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 } |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
82 listen 127.0.0.1:8080; |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 server_name ~^(?P<name>.+)\Q.example.com\E$; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 location / { |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 add_header X-Server $server_name; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 add_header X-Match $name; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 } |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 } |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
92 listen 127.0.0.1:8080; |
171
cfb8147f19a7
Tests: use (?P<name>...) to be compatible with old PCRE versions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
93 server_name "~^(?P<name>www\p{N}+)\.example\.com$"; |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 location / { |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 add_header X-Server $server_name; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 add_header X-Match $name; |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 } |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 } |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
100 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
101 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
102 listen 127.0.0.1:8080; |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
103 server_name many.example.com many2.example.com; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
104 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
105 location / { |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
106 add_header X-Server $server_name; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
107 } |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
108 } |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
109 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
110 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
111 listen 127.0.0.1:8080; |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
112 server_name many3.example.com; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
113 server_name many4.example.com; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
114 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
115 location / { |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
116 add_header X-Server $server_name; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
117 } |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
118 } |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
119 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
120 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
121 listen 127.0.0.1:8080; |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
122 server_name *.wc.example.com; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
123 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
124 location / { |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
125 add_header X-Server $server_name; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
126 } |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
127 } |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
128 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
129 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
130 listen 127.0.0.1:8080; |
689
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
131 server_name *.pref.wc.example.com; |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
132 |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
133 location / { |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
134 add_header X-Server $server_name; |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
135 } |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
136 } |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
137 |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
138 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
139 listen 127.0.0.1:8080; |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
140 server_name wc2.example.*; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
141 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
142 location / { |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
143 add_header X-Server $server_name; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
144 } |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
145 } |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
146 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
147 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
148 listen 127.0.0.1:8080; |
689
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
149 server_name wc2.example.com.*; |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
150 |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
151 location / { |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
152 add_header X-Server $server_name; |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
153 } |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
154 } |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
155 |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
156 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
157 listen 127.0.0.1:8080; |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
158 server_name .dot.example.com; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
159 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
160 location / { |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
161 add_header X-Server $server_name; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
162 } |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
163 } |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
164 } |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
165 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
166 EOF |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
167 |
682 | 168 $t->write_file('index.html', ''); |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
169 $t->run(); |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
170 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
171 ############################################################################### |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
172 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
173 like(http_server('xxx'), qr/X-Server: localhost/, 'default'); |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
174 unlike(http_server(), qr/X-Server/, 'empty'); |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
175 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
176 like(http_server('www.example.com'), qr/\QX-Server: www.example.com/, |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
177 'www.example.com'); |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
178 like(http_server('WWW.EXAMPLE.COM'), qr/\QX-Server: www.example.com/, |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
179 'www.example.com uppercase'); |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
180 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
181 like(http_server('example.com'), qr/\QX-Server: ~^EXAMPLE\.COM$/, |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
182 'example.com regex'); |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
183 like(http_server('EXAMPLE.COM'), qr/\QX-Server: ~^EXAMPLE\.COM$/, |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
184 'example.com regex uppercase'); |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
185 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
186 like(http_server('blah.example.com'), qr/X-Match: blah/, |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
187 '(P<name>.*).example.com named capture'); |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
188 like(http_server('BLAH.EXAMPLE.COM'), qr/X-Match: blah/, |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
189 '(P<name>.*).example.com named capture uppercase'); |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
190 |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
191 like(http_server('www01.example.com'), qr/X-Match: www01/, |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
192 '\p{N} in named capture'); |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
193 like(http_server('WWW01.EXAMPLE.COM'), qr/X-Match: www01/, |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
194 '\p{N} in named capture uppercase'); |
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
195 |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
196 like(http_server('many.example.com'), qr/\QX-Server: many.example.com/, |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
197 'name row - first'); |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
198 like(http_server('many2.example.com'), qr/\QX-Server: many.example.com/, |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
199 'name row - second'); |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
200 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
201 like(http_server('many3.example.com'), qr/\QX-Server: many3.example.com/, |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
202 'name list - first'); |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
203 like(http_server('many4.example.com'), qr/\QX-Server: many3.example.com/, |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
204 'name list - second'); |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
205 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
206 like(http_server('www.wc.example.com'), |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
207 qr/\QX-Server: *.wc.example.com/, 'wildcard first'); |
689
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
208 like(http_server('www.pref.wc.example.com'), |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
209 qr/\QX-Server: *.pref.wc.example.com/, 'wildcard first most specific'); |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
210 like(http_server('wc2.example.net'), |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
211 qr/\QX-Server: wc2.example.*/, 'wildcard last'); |
689
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
212 like(http_server('wc2.example.com.pref'), |
26f58787c6b4
Tests: added server name tests for most specific wildcard names.
Sergey Kandaurov <pluknet@nginx.com>
parents:
683
diff
changeset
|
213 qr/\QX-Server: wc2.example.com.*/, 'wildcard last most specific'); |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
214 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
215 like(http_server('www.dot.example.com'), qr/\QX-Server: dot.example.com/, |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
216 'wildcard dot'); |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
217 like(http_server('dot.example.com'), qr/\QX-Server: dot.example.com/, |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
218 'wildcard dot empty'); |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
219 |
114
44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
220 ############################################################################### |
682 | 221 |
222 sub http_server { | |
223 my ($host) = @_; | |
224 | |
683
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
225 my $str = 'GET / HTTP/1.0' . CRLF . |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
226 (defined $host ? "Host: $host" . CRLF : '') . |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
227 CRLF; |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
228 |
49aea425392d
Tests: more tests for server_name directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
682
diff
changeset
|
229 return http($str); |
682 | 230 } |
231 | |
232 ############################################################################### |