comparison range.t @ 491:d5bf5942a8b2

Tests: disambiguated parsing of the status code.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 07 Nov 2014 13:05:07 +0300
parents 8e8636a4fe61
children dc2f8aac0553
comparison
equal deleted inserted replaced
490:65d2d372ee31 491:d5bf5942a8b2
73 ############################################################################### 73 ###############################################################################
74 74
75 my $t1; 75 my $t1;
76 76
77 $t1 = http_get_range('/t1.html', 'Range: bytes=0-8'); 77 $t1 = http_get_range('/t1.html', 'Range: bytes=0-8');
78 like($t1, qr/206/, 'range request - 206 partial reply'); 78 like($t1, qr/ 206 /, 'range request - 206 partial reply');
79 like($t1, qr/Content-Length: 9/, 'range request - correct length'); 79 like($t1, qr/Content-Length: 9/, 'range request - correct length');
80 like($t1, qr/Content-Range: bytes 0-8\/1000/, 'range request - content range'); 80 like($t1, qr/Content-Range: bytes 0-8\/1000/, 'range request - content range');
81 like($t1, qr/^X000XXXXX$/m, 'range request - correct content'); 81 like($t1, qr/^X000XXXXX$/m, 'range request - correct content');
82 82
83 $t1 = http_get_range('/t1.html', 'Range: bytes=-10'); 83 $t1 = http_get_range('/t1.html', 'Range: bytes=-10');
84 like($t1, qr/206/, 'final bytes - 206 partial reply'); 84 like($t1, qr/ 206 /, 'final bytes - 206 partial reply');
85 like($t1, qr/Content-Length: 10/, 'final bytes - content length'); 85 like($t1, qr/Content-Length: 10/, 'final bytes - content length');
86 like($t1, qr/Content-Range: bytes 990-999\/1000/, 86 like($t1, qr/Content-Range: bytes 990-999\/1000/,
87 'final bytes - content range'); 87 'final bytes - content range');
88 like($t1, qr/^X099XXXXXX$/m, 'final bytes - correct content'); 88 like($t1, qr/^X099XXXXXX$/m, 'final bytes - correct content');
89 89
90 $t1 = http_get_range('/t1.html', 'Range: bytes=990-'); 90 $t1 = http_get_range('/t1.html', 'Range: bytes=990-');
91 like($t1, qr/206/, 'final bytes explicit - 206 partial reply'); 91 like($t1, qr/ 206 /, 'final bytes explicit - 206 partial reply');
92 like($t1, qr/Content-Length: 10/, 'final bytes explicit - content length'); 92 like($t1, qr/Content-Length: 10/, 'final bytes explicit - content length');
93 like($t1, qr/Content-Range: bytes 990-999\/1000/, 93 like($t1, qr/Content-Range: bytes 990-999\/1000/,
94 'final bytes explicit - content range'); 94 'final bytes explicit - content range');
95 like($t1, qr/^X099XXXXXX$/m, 'final bytes explicit - correct content'); 95 like($t1, qr/^X099XXXXXX$/m, 'final bytes explicit - correct content');
96 96
97 $t1 = http_get_range('/t1.html', 'Range: bytes=990-1990'); 97 $t1 = http_get_range('/t1.html', 'Range: bytes=990-1990');
98 like($t1, qr/206/, 'more than length - 206 partial reply'); 98 like($t1, qr/ 206 /, 'more than length - 206 partial reply');
99 like($t1, qr/Content-Length: 10/, 'more than length - content length'); 99 like($t1, qr/Content-Length: 10/, 'more than length - content length');
100 like($t1, qr/Content-Range: bytes 990-999\/1000/, 100 like($t1, qr/Content-Range: bytes 990-999\/1000/,
101 'more than length - content range'); 101 'more than length - content range');
102 like($t1, qr/^X099XXXXXX$/m, 'more than length - correct content'); 102 like($t1, qr/^X099XXXXXX$/m, 'more than length - correct content');
103 103
104 $t1 = http_get_range('/t2.html', 'Range: bytes=990-1990'); 104 $t1 = http_get_range('/t2.html', 'Range: bytes=990-1990');
105 like($t1, qr/206/, 'recoded - 206 partial reply'); 105 like($t1, qr/ 206 /, 'recoded - 206 partial reply');
106 like($t1, qr/Content-Length: 10/, 'recoded - content length'); 106 like($t1, qr/Content-Length: 10/, 'recoded - content length');
107 like($t1, qr/Content-Range: bytes 990-999\/1000/, 'recoded - content range'); 107 like($t1, qr/Content-Range: bytes 990-999\/1000/, 'recoded - content range');
108 like($t1, qr/^Y099YYYYYY$/m, 'recoded - correct content'); 108 like($t1, qr/^Y099YYYYYY$/m, 'recoded - correct content');
109 109
110 $t1 = http_get_range('/t1.html', 'Range: bytes=0-9, -10, 10-19'); 110 $t1 = http_get_range('/t1.html', 'Range: bytes=0-9, -10, 10-19');
111 like($t1, qr/206/, 'multipart - 206 partial reply'); 111 like($t1, qr/ 206 /, 'multipart - 206 partial reply');
112 like($t1, qr/Content-Type: multipart\/byteranges; boundary=/, 112 like($t1, qr/Content-Type: multipart\/byteranges; boundary=/,
113 'multipart - content type'); 113 'multipart - content type');
114 like($t1, qr/X000XXXXXX/m, 'multipart - content 0-9'); 114 like($t1, qr/X000XXXXXX/m, 'multipart - content 0-9');
115 like($t1, qr/^X099XXXXXX\x0d?$/m, 'multipart - content -10 aka 990-999'); 115 like($t1, qr/^X099XXXXXX\x0d?$/m, 'multipart - content -10 aka 990-999');
116 like($t1, qr/X001XXXXXX\x0d?$/m, 'multipart - content 10-19'); 116 like($t1, qr/X001XXXXXX\x0d?$/m, 'multipart - content 10-19');
117 117
118 $t1 = http_get_range('/t1.html', 'Range: bytes=0-9, -10, 100000-, 10-19'); 118 $t1 = http_get_range('/t1.html', 'Range: bytes=0-9, -10, 100000-, 10-19');
119 like($t1, qr/206/, 'multipart big - 206 partial reply'); 119 like($t1, qr/ 206 /, 'multipart big - 206 partial reply');
120 like($t1, qr/Content-Type: multipart\/byteranges; boundary=/, 120 like($t1, qr/Content-Type: multipart\/byteranges; boundary=/,
121 'multipart big - content type'); 121 'multipart big - content type');
122 like($t1, qr/X000XXXXXX/m, 'multipart big - content 0-9'); 122 like($t1, qr/X000XXXXXX/m, 'multipart big - content 0-9');
123 like($t1, qr/^X099XXXXXX\x0d?$/m, 'multipart big - content -10 aka 990-999'); 123 like($t1, qr/^X099XXXXXX\x0d?$/m, 'multipart big - content -10 aka 990-999');
124 like($t1, qr/X001XXXXXX\x0d?$/m, 'multipart big - content 10-19'); 124 like($t1, qr/X001XXXXXX\x0d?$/m, 'multipart big - content 10-19');
125 125
126 like(http_get_range('/t1.html', 'Range: bytes=100000-'), qr/416/, 126 like(http_get_range('/t1.html', 'Range: bytes=100000-'), qr/ 416 /,
127 'not satisfiable - too big first byte pos'); 127 'not satisfiable - too big first byte pos');
128 like(http_get_range('/t1.html', 'Range: bytes=alpha'), qr/416/, 128 like(http_get_range('/t1.html', 'Range: bytes=alpha'), qr/ 416 /,
129 'not satisfiable - alpha in first byte pos'); 129 'not satisfiable - alpha in first byte pos');
130 like(http_get_range('/t1.html', 'Range: bytes=10-alpha'), qr/416/, 130 like(http_get_range('/t1.html', 'Range: bytes=10-alpha'), qr/ 416 /,
131 'not satisfiable - alpha in last byte pos'); 131 'not satisfiable - alpha in last byte pos');
132 like(http_get_range('/t1.html', 'Range: bytes=10'), qr/416/, 132 like(http_get_range('/t1.html', 'Range: bytes=10'), qr/ 416 /,
133 'not satisfiable - no hyphen'); 133 'not satisfiable - no hyphen');
134 like(http_get_range('/t1.html', 'Range: bytes=10-11 12-'), qr/416/, 134 like(http_get_range('/t1.html', 'Range: bytes=10-11 12-'), qr/ 416 /,
135 'not satisfiable - no comma'); 135 'not satisfiable - no comma');
136 136
137 # last-byte-pos is taken to be equal to one less than the current length 137 # last-byte-pos is taken to be equal to one less than the current length
138 # of the entity-body in bytes -- rfc2616 sec 14.35. 138 # of the entity-body in bytes -- rfc2616 sec 14.35.
139 139
140 like(http_get_range('/t1.html', 'Range: bytes=0-10001'), qr/206/, 140 like(http_get_range('/t1.html', 'Range: bytes=0-10001'), qr/ 206 /,
141 'satisfiable - last byte pos adjusted'); 141 'satisfiable - last byte pos adjusted');
142 142
143 # total size of all ranges is greater than source response size 143 # total size of all ranges is greater than source response size
144 144
145 like(http_get_range('/t1.html', 'Range: bytes=0-10001, 0-0'), qr/200/, 145 like(http_get_range('/t1.html', 'Range: bytes=0-10001, 0-0'), qr/ 200 /,
146 'not satisfiable - malicious byte ranges'); 146 'not satisfiable - malicious byte ranges');
147 147
148 like(http_get_range('/t3.html', 'Range: bytes=0-9, -10'), qr/206/, 148 like(http_get_range('/t3.html', 'Range: bytes=0-9, -10'), qr/ 206 /,
149 'max_ranges not reached'); 149 'max_ranges not reached');
150 like(http_get_range('/t3.html', 'Range: bytes=0-9, -10, 10000-'), qr/206/, 150 like(http_get_range('/t3.html', 'Range: bytes=0-9, -10, 10000-'), qr/ 206 /,
151 'max_ranges not reached bad range'); 151 'max_ranges not reached bad range');
152 unlike(http_get_range('/t3.html', 'Range: bytes=0-9, -10, 10-19'), 152 unlike(http_get_range('/t3.html', 'Range: bytes=0-9, -10, 10-19'),
153 qr/206/, 'max_ranges reached'); 153 qr/ 206 /, 'max_ranges reached');
154 unlike(http_get_range('/t4.html', 'Range: bytes=0-9'), qr/206/, 154 unlike(http_get_range('/t4.html', 'Range: bytes=0-9'), qr/ 206 /,
155 'max_ranges zero'); 155 'max_ranges zero');
156 156
157 ############################################################################### 157 ###############################################################################
158 158
159 sub http_get_range { 159 sub http_get_range {