Mercurial > hg > nginx-tests
annotate range.t @ 103:4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
1. Make sure rejected requests are not counted, as leaky bucket algorithm
suggests (finally correctly done in 0.8.18).
2. Make sure negative excess values are handled properly (bug appeared in
0.8.18, fixed in 0.8.19).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 09 Oct 2009 21:05:42 +0400 |
parents | 726c3c2a8b8c |
children | 1c0ec30614c6 |
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 | |
28 master_process off; | |
29 daemon off; | |
30 | |
31 events { | |
32 } | |
33 | |
34 http { | |
35 access_log off; | |
36 root %%TESTDIR%%; | |
37 | |
35
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
33
diff
changeset
|
38 client_body_temp_path %%TESTDIR%%/client_body_temp; |
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
33
diff
changeset
|
39 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; |
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
33
diff
changeset
|
40 proxy_temp_path %%TESTDIR%%/proxy_temp; |
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
33
diff
changeset
|
41 |
33 | 42 charset_map B A { |
43 58 59; # X -> Y | |
44 } | |
45 | |
46 server { | |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
35
diff
changeset
|
47 listen 127.0.0.1:8080; |
33 | 48 server_name localhost; |
49 | |
50 location /t2.html { | |
51 charset A; | |
52 source_charset B; | |
53 } | |
54 } | |
55 } | |
56 | |
57 EOF | |
58 | |
59 $t->write_file('t1.html', | |
60 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); | |
61 $t->write_file('t2.html', | |
62 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); | |
63 $t->run(); | |
64 | |
65 ############################################################################### | |
66 | |
67 my $t1; | |
68 | |
69 $t1 = http_get_range('/t1.html', 'Range: bytes=0-8'); | |
70 like($t1, qr/206/, 'range request - 206 partial reply'); | |
71 like($t1, qr/Content-Length: 9/, 'range request - correct length'); | |
72 like($t1, qr/Content-Range: bytes 0-8\/1000/, 'range request - content range'); | |
73 like($t1, qr/^X000XXXXX$/m, 'range request - correct content'); | |
74 | |
75 $t1 = http_get_range('/t1.html', 'Range: bytes=-10'); | |
76 like($t1, qr/206/, 'final bytes - 206 partial reply'); | |
77 like($t1, qr/Content-Length: 10/, 'final bytes - content length'); | |
78 like($t1, qr/Content-Range: bytes 990-999\/1000/, | |
79 'final bytes - content range'); | |
80 like($t1, qr/^X099XXXXXX$/m, 'final bytes - correct content'); | |
81 | |
82 $t1 = http_get_range('/t1.html', 'Range: bytes=990-'); | |
83 like($t1, qr/206/, 'final bytes explicit - 206 partial reply'); | |
84 like($t1, qr/Content-Length: 10/, 'final bytes explicit - content length'); | |
85 like($t1, qr/Content-Range: bytes 990-999\/1000/, | |
86 'final bytes explicit - content range'); | |
87 like($t1, qr/^X099XXXXXX$/m, 'final bytes explicit - correct content'); | |
88 | |
89 $t1 = http_get_range('/t1.html', 'Range: bytes=990-1990'); | |
90 like($t1, qr/206/, 'more than length - 206 partial reply'); | |
91 like($t1, qr/Content-Length: 10/, 'more than length - content length'); | |
92 like($t1, qr/Content-Range: bytes 990-999\/1000/, | |
93 'more than length - content range'); | |
94 like($t1, qr/^X099XXXXXX$/m, 'more than length - correct content'); | |
95 | |
96 $t1 = http_get_range('/t2.html', 'Range: bytes=990-1990'); | |
97 like($t1, qr/206/, 'recoded - 206 partial reply'); | |
98 like($t1, qr/Content-Length: 10/, 'recoded - content length'); | |
99 like($t1, qr/Content-Range: bytes 990-999\/1000/, 'recoded - content range'); | |
100 like($t1, qr/^Y099YYYYYY$/m, 'recoded - correct content'); | |
101 | |
102 $t1 = http_get_range('/t1.html', 'Range: bytes=0-9, -10, 10-19'); | |
103 like($t1, qr/206/, 'multipart - 206 partial reply'); | |
104 like($t1, qr/Content-Type: multipart\/byteranges; boundary=/, | |
105 'multipart - content type'); | |
106 like($t1, qr/X000XXXXXX/m, 'multipart - content 0-9'); | |
107 like($t1, qr/^X099XXXXXX\x0d?$/m, 'multipart - content -10 aka 990-999'); | |
108 like($t1, qr/X001XXXXXX\x0d?$/m, 'multipart - content 10-19'); | |
109 | |
110 ############################################################################### | |
111 | |
112 sub http_get_range { | |
113 my ($url, $extra) = @_; | |
114 return http(<<EOF); | |
115 GET $url HTTP/1.1 | |
116 Host: localhost | |
117 Connection: close | |
118 $extra | |
119 | |
120 EOF | |
121 } | |
122 | |
123 ############################################################################### |