8
|
1 #!/usr/bin/perl
|
|
2
|
|
3 # (C) Maxim Dounin
|
|
4
|
|
5 # Tests for compose 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
|
|
20 my $t = Test::Nginx->new()->plan(16);
|
|
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
|
|
42 location /compose {
|
|
43 compose on;
|
|
44
|
|
45 add_header X-Compose-Length 4000;
|
|
46 add_header X-Compose /t1?1;
|
|
47 add_header X-Compose /t1?2;
|
|
48 add_header X-Compose /t1?3;
|
|
49 add_header X-Compose /t1?4;
|
|
50
|
|
51 empty_gif;
|
|
52 }
|
|
53
|
|
54 location /compose-big {
|
|
55 compose on;
|
|
56
|
|
57 add_header X-Compose /tbig?1;
|
|
58 add_header X-Compose /tbig?2;
|
|
59 add_header X-Compose /tbig?3;
|
|
60 add_header X-Compose /tbig?4;
|
|
61
|
|
62 empty_gif;
|
|
63 }
|
|
64 }
|
|
65 }
|
|
66
|
|
67 EOF
|
|
68
|
|
69 $t->write_file('t1',
|
|
70 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99)));
|
|
71 $t->write_file('tbig', 'X' x (1 * 1024 * 1024));
|
|
72 $t->run();
|
|
73
|
|
74 ###############################################################################
|
|
75
|
|
76 my $t1;
|
|
77
|
|
78 # normal requests
|
|
79
|
|
80 $t1 = http_get('/compose');
|
|
81 like($t1, qr/ 200 /, 'full reply');
|
|
82 like($t1, qr/Content-Length: 4000/, 'full reply length');
|
|
83 like($t1, qr/^(X[0-9]{3}XXXXXX){400}$/m, 'full reply content');
|
|
84
|
|
85 # various range requests
|
|
86
|
|
87 $t1 = http_get_range('/compose', 'Range: bytes=0-9');
|
|
88 like($t1, qr/206/, 'first bytes - 206 partial reply');
|
|
89 like($t1, qr/Content-Length: 10/, 'first bytes - correct length');
|
|
90 like($t1, qr/Content-Range: bytes 0-9\/4000/, 'first bytes - content range');
|
|
91 like($t1, qr/^X000X{6}$/m, 'first bytes - correct content');
|
|
92
|
|
93 $t1 = http_get_range('/compose', 'Range: bytes=-10');
|
|
94 like($t1, qr/ 206 /, 'final bytes - 206 partial reply');
|
|
95 like($t1, qr/Content-Length: 10/, 'final bytes - content length');
|
|
96 like($t1, qr/Content-Range: bytes 3990-3999\/4000/,
|
|
97 'final bytes - content range');
|
|
98 like($t1, qr/^X099XXXXXX$/m, 'final bytes - correct content');
|
|
99
|
|
100 $t1 = http_get_range('/compose', 'Range: bytes=900-1099');
|
|
101 like($t1, qr/ 206 /, 'multi buffers - 206 partial reply');
|
|
102 like($t1, qr/Content-Length: 200/, 'multi buffers - content length');
|
|
103 like($t1, qr/Content-Range: bytes 900-1099\/4000/, 'multi buffers - content range');
|
|
104 like($t1, qr/^(X09[0-9]XXXXXX){10}(X00[0-9]XXXXXX){10}$/m,
|
|
105 'multi buffers - correct content');
|
|
106
|
|
107 # big files
|
|
108
|
|
109 $t1 = http_get('/compose-big');
|
|
110 cmp_ok(length($t1), '>', 4 * 1024 * 1024, 'big files - correct length');
|
|
111
|
|
112 ###############################################################################
|
|
113
|
|
114 sub http_get_range {
|
|
115 my ($url, $extra) = @_;
|
|
116 return http(<<EOF);
|
|
117 GET $url HTTP/1.1
|
|
118 Host: localhost
|
|
119 Connection: close
|
|
120 $extra
|
|
121
|
|
122 EOF
|
|
123 }
|
|
124
|
|
125 ###############################################################################
|