Mercurial > hg > ngx_http_bytes_filter_module
annotate t/bytes.t @ 17:314242bda1c1
Correctly handle last ignored buffer again.
If we ignore buffer marked as last_buf, make sure we pass out empty buffer
marked as last_buf. The same problem was already fixed in rev. 48cdd1bfa48e,
but only for optimized special case (last range and last buffer).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 02 Feb 2009 19:54:12 +0300 |
parents | d6f0d7a8d752 |
children |
rev | line source |
---|---|
15 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for bytes filter module. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 use Test::Nginx; | |
14 | |
15 ############################################################################### | |
16 | |
17 select STDERR; $| = 1; | |
18 select STDOUT; $| = 1; | |
19 | |
17
314242bda1c1
Correctly handle last ignored buffer again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
15
diff
changeset
|
20 my $t = Test::Nginx->new()->plan(25); |
15 | 21 |
22 $t->write_file_expand('nginx.conf', <<'EOF'); | |
23 | |
24 master_process off; | |
25 daemon off; | |
26 | |
27 events { | |
28 } | |
29 | |
30 http { | |
31 access_log off; | |
32 root %%TESTDIR%%; | |
33 | |
34 client_body_temp_path %%TESTDIR%%/client_body_temp; | |
35 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; | |
36 proxy_temp_path %%TESTDIR%%/proxy_temp; | |
37 | |
38 server { | |
39 listen 127.0.0.1:8080; | |
40 server_name localhost; | |
41 location / { | |
42 bytes on; | |
43 } | |
44 } | |
45 } | |
46 | |
47 EOF | |
48 | |
49 $t->write_file('t1', | |
50 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); | |
51 $t->run(); | |
52 | |
53 ############################################################################### | |
54 | |
55 my $t1; | |
56 | |
57 # normal requests | |
58 | |
59 $t1 = http_get('/t1'); | |
60 like($t1, qr/200/, 'full reply'); | |
61 like($t1, qr/Content-Length: 1000/, 'full reply length'); | |
62 like($t1, qr/^(X[0-9]{3}XXXXXX){100}$/m, 'full reply content'); | |
63 | |
64 $t1 = http_get('/t1?bytes=0-'); | |
65 like($t1, qr/200/, 'full reply filtered'); | |
66 like($t1, qr/Content-Length: 1000/, 'full reply filtered length'); | |
67 like($t1, qr/^(X[0-9]{3}XXXXXX){100}$/m, 'full reply filtered content'); | |
68 | |
69 $t1 = http_get('/t1?bytes=0-9,100-109,990-'); | |
70 like($t1, qr/200/, 'complex reply'); | |
71 like($t1, qr/Content-Length: 30/, 'complex reply length'); | |
72 like($t1, qr/^(X[0-9]{3}XXXXXX){3}$/m, 'complex reply content'); | |
73 | |
74 $t1 = http_get('/t1?bytes=-10'); | |
75 like($t1, qr/200/, 'final bytes'); | |
76 like($t1, qr/Content-Length: 10/, 'final bytes length'); | |
77 like($t1, qr/^X099XXXXXX$/m, 'final bytes content'); | |
78 | |
17
314242bda1c1
Correctly handle last ignored buffer again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
15
diff
changeset
|
79 # standard error pages contain multiple buffers in one chain |
314242bda1c1
Correctly handle last ignored buffer again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
15
diff
changeset
|
80 |
314242bda1c1
Correctly handle last ignored buffer again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
15
diff
changeset
|
81 like(http_get('/notfound?bytes=0-9'), qr/404/, 'not found'); |
314242bda1c1
Correctly handle last ignored buffer again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
15
diff
changeset
|
82 |
15 | 83 # various range requests |
84 | |
85 $t1 = http_get_range('/t1?bytes=100-', 'Range: bytes=0-9'); | |
86 like($t1, qr/206/, 'first bytes - 206 partial reply'); | |
87 like($t1, qr/Content-Length: 10/, 'first bytes - correct length'); | |
88 like($t1, qr/Content-Range: bytes 0-9\/900/, 'first bytes - content range'); | |
89 like($t1, qr/^X010X{6}$/m, 'first bytes - correct content'); | |
90 | |
91 $t1 = http_get_range('/t1?bytes=100-', 'Range: bytes=-10'); | |
92 like($t1, qr/206/, 'final bytes - 206 partial reply'); | |
93 like($t1, qr/Content-Length: 10/, 'final bytes - content length'); | |
94 like($t1, qr/Content-Range: bytes 890-899\/900/, | |
95 'final bytes - content range'); | |
96 like($t1, qr/^X099XXXXXX$/m, 'final bytes - correct content'); | |
97 | |
98 $t1 = http_get_range('/t1?bytes=0-12,100-', 'Range: bytes=0-99'); | |
99 like($t1, qr/206/, 'multi buffers - 206 partial reply'); | |
100 like($t1, qr/Content-Length: 100/, 'multi buffers - content length'); | |
101 like($t1, qr/Content-Range: bytes 0-99\/913/, 'multi buffers - content range'); | |
102 like($t1, qr/^X000X{6}X00X010XXXXXX(X01[1-7]XXXXXX){7}X018XXX$/m, | |
103 'multi buffers - correct content'); | |
104 | |
105 ############################################################################### | |
106 | |
107 sub http_get_range { | |
108 my ($url, $extra) = @_; | |
109 return http(<<EOF); | |
110 GET $url HTTP/1.1 | |
111 Host: localhost | |
112 Connection: close | |
113 $extra | |
114 | |
115 EOF | |
116 } | |
117 | |
118 ############################################################################### |