comparison range_charset.t @ 373:1e6e216b06c2

Tests: range filter tests with charset.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 13 Feb 2014 15:21:44 +0400
parents
children 847ea345becb
comparison
equal deleted inserted replaced
372:1d6abf0db011 373:1e6e216b06c2
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for range filter on proxied response with charset.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 plan(skip_all => 'win32') if $^O eq 'MSWin32';
26
27 my $t = Test::Nginx->new()->has(qw/http proxy cache charset/)->plan(10)
28 ->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 daemon off;
33
34 events {
35 }
36
37 http {
38 %%TEST_GLOBALS_HTTP%%
39
40 charset_map B A {
41 58 59; # X -> Y
42 }
43
44 proxy_cache_path %%TESTDIR%%/cache levels=1:2
45 keys_zone=NAME:1m;
46
47 server {
48 listen 127.0.0.1:8080;
49 server_name localhost;
50
51 location / {
52 proxy_pass http://127.0.0.1:8081;
53 proxy_cache NAME;
54 proxy_cache_valid 200 1m;
55 }
56 }
57
58 server {
59 listen 127.0.0.1:8081;
60 server_name localhost;
61
62 charset B;
63
64 location /t2.html {
65 add_header X-Accel-Charset A;
66 }
67 }
68 }
69
70 EOF
71
72 $t->write_file('t1.html',
73 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99)));
74 $t->write_file('t2.html',
75 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99)));
76 $t->run();
77
78 ###############################################################################
79
80 my $t1;
81
82 # range request on proxied response with charset attribute in content-type
83 # NB: to get partial content, requests need to be served from cache
84
85 http_get('/t1.html');
86 $t1 = http_get_range('/t1.html', 'Range: bytes=0-9, 10-19');
87 like($t1, qr/206/, 'charset - 206 partial reply');
88 like($t1, qr/Content-Type: multipart\/byteranges; boundary=\w+\x0d\x0a/,
89 'charset - content type');
90
91 TODO: {
92 local $TODO = 'not yet' unless $t->has_version('1.5.11');
93
94 like($t1, qr/Content-Type: text\/html; charset=B(?!; charset)/,
95 'charset - charset attribute');
96 }
97
98 like($t1, qr/X000XXXXXX/m, 'charset - content 0-9');
99 like($t1, qr/X001XXXXXX\x0d?$/m, 'charset - content 10-19');
100
101 http_get('/t2.html');
102 $t1 = http_get_range('/t2.html', 'Range: bytes=0-9, 10-19');
103 like($t1, qr/206/, 'x-accel-charset - 206 partial reply');
104 like($t1, qr/Content-Type: multipart\/byteranges; boundary=\w+\x0d\x0a/,
105 'x-accel-charset - content type');
106 like($t1, qr/Content-Type: text\/html; charset=A(?!; charset)/,
107 'x-accel-charset - charset attribute');
108 like($t1, qr/Y000YYYYYY/m, 'x-accel-charset - content 0-9');
109 like($t1, qr/Y001YYYYYY\x0d?$/m, 'x-accel-charset - content 10-19');
110
111 ###############################################################################
112
113 sub http_get_range {
114 my ($url, $extra) = @_;
115 return http(<<EOF);
116 GET $url HTTP/1.1
117 Host: localhost
118 Connection: close
119 $extra
120
121 EOF
122 }
123
124 ###############################################################################