comparison range_clearing.t @ 1809:c41ac260299f

Tests: clearing of pre-existing Content-Range headers.
author Eugene Grebenschikov <e.grebenshchikov@nginx.com>
date Fri, 18 Nov 2022 09:52:36 -0800
parents
children
comparison
equal deleted inserted replaced
1808:6040bfd6acbd 1809:c41ac260299f
1 #!/usr/bin/perl
2
3 # (C) Eugene Grebenschikov
4 # (C) Sergey Kandaurov
5 # (C) Nginx, Inc.
6
7 # Tests for clearing of pre-existing Content-Range headers.
8
9 ###############################################################################
10
11 use warnings;
12 use strict;
13
14 use Test::More;
15
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
17
18 use lib 'lib';
19 use Test::Nginx;
20
21 ###############################################################################
22
23 select STDERR; $| = 1;
24 select STDOUT; $| = 1;
25
26 my $t = Test::Nginx->new()->has(qw/http rewrite proxy cache/)
27 ->write_file_expand('nginx.conf', <<'EOF');
28
29 %%TEST_GLOBALS%%
30
31 daemon off;
32
33 events {
34 }
35
36 http {
37 %%TEST_GLOBALS_HTTP%%
38
39 proxy_cache_path %%TESTDIR%%/cache levels=1:2 keys_zone=NAME:1m;
40
41 server {
42 listen 127.0.0.1:8080;
43 server_name localhost;
44
45 location / {
46 proxy_pass http://127.0.0.1:8080/stub;
47 proxy_cache NAME;
48 proxy_cache_valid 200 1m;
49 }
50
51 location /stub {
52 add_header Content-Range stub;
53 add_header Accept-Ranges bytes;
54 return 200 "SEE-THIS";
55 }
56 }
57 }
58
59 EOF
60
61 $t->run()->plan(3);
62
63 ###############################################################################
64
65 local $TODO = 'not yet' unless $t->has_version('1.23.1');
66
67 like(http_get_range('/', 'Range: bytes=0-4'),
68 qr/ 206 (?!.*stub)/s, 'content range cleared - range request');
69 like(http_get_range('/', 'Range: bytes=0-2,4-'),
70 qr/ 206 (?!.*stub)/s, 'content range cleared - multipart');
71 like(http_get_range('/', 'Range: bytes=1000-'),
72 qr/ 416 (?!.*stub)/s, 'content range cleared - not satisfable');
73
74 ###############################################################################
75
76 sub http_get_range {
77 my ($url, $extra) = @_;
78 return http(<<EOF);
79 GET $url HTTP/1.1
80 Host: localhost
81 Connection: close
82 $extra
83
84 EOF
85 }
86
87 ###############################################################################