Mercurial > hg > nginx-tests
comparison range-flv.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()->has('flv')->plan(12); | |
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 server { | |
40 listen localhost:8080; | |
41 server_name localhost; | |
42 location / { | |
43 flv; | |
44 } | |
45 } | |
46 } | |
47 | |
48 EOF | |
49 | |
50 $t->write_file('t1.flv', | |
51 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); | |
52 $t->run(); | |
53 | |
54 ############################################################################### | |
55 | |
56 my $t1; | |
57 | |
58 # FLV has 13 byte header at start. | |
59 | |
60 $t1 = http_get_range('/t1.flv?start=100', 'Range: bytes=0-9'); | |
61 like($t1, qr/206/, 'first bytes - 206 partial reply'); | |
62 like($t1, qr/Content-Length: 10/, 'first bytes - correct length'); | |
63 like($t1, qr/Content-Range: bytes 0-9\/913/, 'first bytes - content range'); | |
64 like($t1, qr/^FLV.{7}$/m, 'first bytes - correct content'); | |
65 | |
66 $t1 = http_get_range('/t1.flv?start=100', 'Range: bytes=-10'); | |
67 like($t1, qr/206/, 'final bytes - 206 partial reply'); | |
68 like($t1, qr/Content-Length: 10/, 'final bytes - content length'); | |
69 like($t1, qr/Content-Range: bytes 903-912\/913/, | |
70 'final bytes - content range'); | |
71 like($t1, qr/^X099XXXXXX$/m, 'final bytes - correct content'); | |
72 | |
73 $t1 = http_get_range('/t1.flv?start=100', 'Range: bytes=0-99'); | |
74 like($t1, qr/206/, 'multi buffers - 206 partial reply'); | |
75 like($t1, qr/Content-Length: 100/, 'multi buffers - content length'); | |
76 like($t1, qr/Content-Range: bytes 0-99\/913/, 'multi buffers - content range'); | |
77 like($t1, qr/^FLV.{10}X010XXXXXX(X01[1-7]XXXXXX){7}X018XXX$/m, | |
78 'multi buffers - correct content'); | |
79 | |
80 ############################################################################### | |
81 | |
82 sub http_get_range { | |
83 my ($url, $extra) = @_; | |
84 return http(<<EOF); | |
85 GET $url HTTP/1.1 | |
86 Host: localhost | |
87 Connection: close | |
88 $extra | |
89 | |
90 EOF | |
91 } | |
92 | |
93 ############################################################################### |