blob: 0653a16a805586e3a03800256197e1bc23b940b7 [file] [log] [blame]
Maxim Dounina01dff62008-10-14 02:18:03 +04001#!/usr/bin/perl
2
3# (C) Maxim Dounin
4
5# Tests for range filter module.
6
7###############################################################################
8
9use warnings;
10use strict;
11
12use Test::More;
13
14BEGIN { use FindBin; chdir($FindBin::Bin); }
15
16use lib 'lib';
17use Test::Nginx;
18
19###############################################################################
20
21select STDERR; $| = 1;
22select STDOUT; $| = 1;
23
24my $t = Test::Nginx->new()->has('flv')->plan(12);
25
26$t->write_file_expand('nginx.conf', <<'EOF');
27
Maxim Douninc6acedb2009-10-14 02:23:52 +040028%%TEST_GLOBALS%%
29
Maxim Dounina01dff62008-10-14 02:18:03 +040030master_process off;
31daemon off;
32
33events {
Maxim Dounina01dff62008-10-14 02:18:03 +040034}
35
36http {
Maxim Douninc6acedb2009-10-14 02:23:52 +040037 %%TEST_GLOBALS_HTTP%%
Maxim Dounine3aaba52008-10-16 19:16:46 +040038
Maxim Dounina01dff62008-10-14 02:18:03 +040039 server {
Maxim Dounin3c472202008-11-02 15:01:41 +030040 listen 127.0.0.1:8080;
Maxim Dounina01dff62008-10-14 02:18:03 +040041 server_name localhost;
42 location / {
43 flv;
44 }
45 }
46}
47
48EOF
49
50$t->write_file('t1.flv',
51 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99)));
52$t->run();
53
54###############################################################################
55
56my $t1;
57
58# FLV has 13 byte header at start.
59
60$t1 = http_get_range('/t1.flv?start=100', 'Range: bytes=0-9');
61like($t1, qr/206/, 'first bytes - 206 partial reply');
62like($t1, qr/Content-Length: 10/, 'first bytes - correct length');
63like($t1, qr/Content-Range: bytes 0-9\/913/, 'first bytes - content range');
64like($t1, qr/^FLV.{7}$/m, 'first bytes - correct content');
65
66$t1 = http_get_range('/t1.flv?start=100', 'Range: bytes=-10');
67like($t1, qr/206/, 'final bytes - 206 partial reply');
68like($t1, qr/Content-Length: 10/, 'final bytes - content length');
69like($t1, qr/Content-Range: bytes 903-912\/913/,
70 'final bytes - content range');
71like($t1, qr/^X099XXXXXX$/m, 'final bytes - correct content');
72
73$t1 = http_get_range('/t1.flv?start=100', 'Range: bytes=0-99');
74like($t1, qr/206/, 'multi buffers - 206 partial reply');
75like($t1, qr/Content-Length: 100/, 'multi buffers - content length');
76like($t1, qr/Content-Range: bytes 0-99\/913/, 'multi buffers - content range');
77like($t1, qr/^FLV.{10}X010XXXXXX(X01[1-7]XXXXXX){7}X018XXX$/m,
78 'multi buffers - correct content');
79
80###############################################################################
81
82sub http_get_range {
83 my ($url, $extra) = @_;
84 return http(<<EOF);
85GET $url HTTP/1.1
86Host: localhost
87Connection: close
88$extra
89
90EOF
91}
92
93###############################################################################