comparison range.t @ 33:4f57d57543e1

Tests: range filter tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 14 Oct 2008 02:18:03 +0400
parents
children 7bf0e8a1d66c
comparison
equal deleted inserted replaced
32:18296293d18a 33:4f57d57543e1
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 worker_connections 1024;
33 }
34
35 http {
36 access_log off;
37 root %%TESTDIR%%;
38
39 charset_map B A {
40 58 59; # X -> Y
41 }
42
43 server {
44 listen localhost:8080;
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 ###############################################################################