Mercurial > hg > nginx-tests
annotate range.t @ 114:44b281ac4bc6
Tests: add server name tests, including fancy regex ones.
With test config nginx will fail to start as of 0.8.28 due to incorrect
conversion of regular expressions to lowercase. Patch was discussed on
mailing list and will be included in next release.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 30 Nov 2009 14:47:17 +0300 |
parents | 1c0ec30614c6 |
children | 8ac1faaddd2c |
rev | line source |
---|---|
33 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for range filter module. | |
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 my $t = Test::Nginx->new()->plan(25); | |
25 | |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
28 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
29 |
33 | 30 master_process off; |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
35
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
33
diff
changeset
|
38 |
33 | 39 charset_map B A { |
40 58 59; # X -> Y | |
41 } | |
42 | |
43 server { | |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
35
diff
changeset
|
44 listen 127.0.0.1:8080; |
33 | 45 server_name localhost; |
46 | |
47 location /t2.html { | |
48 charset A; | |
49 source_charset B; | |
50 } | |
51 } | |
52 } | |
53 | |
54 EOF | |
55 | |
56 $t->write_file('t1.html', | |
57 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); | |
58 $t->write_file('t2.html', | |
59 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); | |
60 $t->run(); | |
61 | |
62 ############################################################################### | |
63 | |
64 my $t1; | |
65 | |
66 $t1 = http_get_range('/t1.html', 'Range: bytes=0-8'); | |
67 like($t1, qr/206/, 'range request - 206 partial reply'); | |
68 like($t1, qr/Content-Length: 9/, 'range request - correct length'); | |
69 like($t1, qr/Content-Range: bytes 0-8\/1000/, 'range request - content range'); | |
70 like($t1, qr/^X000XXXXX$/m, 'range request - correct content'); | |
71 | |
72 $t1 = http_get_range('/t1.html', 'Range: bytes=-10'); | |
73 like($t1, qr/206/, 'final bytes - 206 partial reply'); | |
74 like($t1, qr/Content-Length: 10/, 'final bytes - content length'); | |
75 like($t1, qr/Content-Range: bytes 990-999\/1000/, | |
76 'final bytes - content range'); | |
77 like($t1, qr/^X099XXXXXX$/m, 'final bytes - correct content'); | |
78 | |
79 $t1 = http_get_range('/t1.html', 'Range: bytes=990-'); | |
80 like($t1, qr/206/, 'final bytes explicit - 206 partial reply'); | |
81 like($t1, qr/Content-Length: 10/, 'final bytes explicit - content length'); | |
82 like($t1, qr/Content-Range: bytes 990-999\/1000/, | |
83 'final bytes explicit - content range'); | |
84 like($t1, qr/^X099XXXXXX$/m, 'final bytes explicit - correct content'); | |
85 | |
86 $t1 = http_get_range('/t1.html', 'Range: bytes=990-1990'); | |
87 like($t1, qr/206/, 'more than length - 206 partial reply'); | |
88 like($t1, qr/Content-Length: 10/, 'more than length - content length'); | |
89 like($t1, qr/Content-Range: bytes 990-999\/1000/, | |
90 'more than length - content range'); | |
91 like($t1, qr/^X099XXXXXX$/m, 'more than length - correct content'); | |
92 | |
93 $t1 = http_get_range('/t2.html', 'Range: bytes=990-1990'); | |
94 like($t1, qr/206/, 'recoded - 206 partial reply'); | |
95 like($t1, qr/Content-Length: 10/, 'recoded - content length'); | |
96 like($t1, qr/Content-Range: bytes 990-999\/1000/, 'recoded - content range'); | |
97 like($t1, qr/^Y099YYYYYY$/m, 'recoded - correct content'); | |
98 | |
99 $t1 = http_get_range('/t1.html', 'Range: bytes=0-9, -10, 10-19'); | |
100 like($t1, qr/206/, 'multipart - 206 partial reply'); | |
101 like($t1, qr/Content-Type: multipart\/byteranges; boundary=/, | |
102 'multipart - content type'); | |
103 like($t1, qr/X000XXXXXX/m, 'multipart - content 0-9'); | |
104 like($t1, qr/^X099XXXXXX\x0d?$/m, 'multipart - content -10 aka 990-999'); | |
105 like($t1, qr/X001XXXXXX\x0d?$/m, 'multipart - content 10-19'); | |
106 | |
107 ############################################################################### | |
108 | |
109 sub http_get_range { | |
110 my ($url, $extra) = @_; | |
111 return http(<<EOF); | |
112 GET $url HTTP/1.1 | |
113 Host: localhost | |
114 Connection: close | |
115 $extra | |
116 | |
117 EOF | |
118 } | |
119 | |
120 ############################################################################### |