Mercurial > hg > nginx-tests
comparison js_headers.t @ 1568:4cc012205ac5
Tests: added js tests for raw headers API.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Wed, 06 May 2020 12:52:17 +0000 |
parents | 5cf2f4da8bd5 |
children | 18ac4d9e5a2a |
comparison
equal
deleted
inserted
replaced
1567:726877fc4b08 | 1568:4cc012205ac5 |
---|---|
98 | 98 |
99 location /hdr_in { | 99 location /hdr_in { |
100 js_content hdr_in; | 100 js_content hdr_in; |
101 } | 101 } |
102 | 102 |
103 location /raw_hdr_in { | |
104 js_content raw_hdr_in; | |
105 } | |
106 | |
103 location /hdr_out { | 107 location /hdr_out { |
104 js_content hdr_out; | 108 js_content hdr_out; |
109 } | |
110 | |
111 location /raw_hdr_out { | |
112 js_content raw_hdr_out; | |
105 } | 113 } |
106 | 114 |
107 location /hdr_out_array { | 115 location /hdr_out_array { |
108 js_content hdr_out_array; | 116 js_content hdr_out_array; |
109 } | 117 } |
214 } | 222 } |
215 | 223 |
216 r.return(200, s); | 224 r.return(200, s); |
217 } | 225 } |
218 | 226 |
227 function raw_hdr_in(r) { | |
228 var filtered = r.rawHeadersIn | |
229 .filter(v=>v[0].toLowerCase() == r.args.filter); | |
230 r.return(200, 'raw:' + filtered.map(v=>v[1]).join('|')); | |
231 } | |
232 | |
219 function hdr_sorted_keys(r) { | 233 function hdr_sorted_keys(r) { |
220 var s = ''; | 234 var s = ''; |
221 var hdr = r.args.in ? r.headersIn : r.headersOut; | 235 var hdr = r.args.in ? r.headersIn : r.headersOut; |
222 | 236 |
223 if (!r.args.in) { | 237 if (!r.args.in) { |
254 | 268 |
255 r.sendHeader(); | 269 r.sendHeader(); |
256 r.finish(); | 270 r.finish(); |
257 } | 271 } |
258 | 272 |
273 function raw_hdr_out(r) { | |
274 r.headersOut.a = ['foo', 'bar']; | |
275 r.headersOut.b = 'b'; | |
276 | |
277 var filtered = r.rawHeadersOut | |
278 .filter(v=>v[0].toLowerCase() == r.args.filter); | |
279 r.return(200, 'raw:' + filtered.map(v=>v[1]).join('|')); | |
280 } | |
281 | |
259 function hdr_out_array(r) { | 282 function hdr_out_array(r) { |
260 if (!r.args.hidden) { | 283 if (!r.args.hidden) { |
261 r.headersOut['Foo'] = [r.args.fOO]; | 284 r.headersOut['Foo'] = [r.args.fOO]; |
262 r.headersOut['Foo'] = []; | 285 r.headersOut['Foo'] = []; |
263 r.headersOut['Foo'] = ['bar', r.args.fOO]; | 286 r.headersOut['Foo'] = ['bar', r.args.fOO]; |
301 } | 324 } |
302 | 325 |
303 | 326 |
304 EOF | 327 EOF |
305 | 328 |
306 $t->try_run('no njs')->plan(37); | 329 $t->try_run('no njs')->plan(39); |
307 | 330 |
308 ############################################################################### | 331 ############################################################################### |
309 | 332 |
310 like(http_get('/content_length'), qr/Content-Length: 3/, | 333 like(http_get('/content_length'), qr/Content-Length: 3/, |
311 'set Content-Length'); | 334 'set Content-Length'); |
412 . 'Foo: bar1' . CRLF | 435 . 'Foo: bar1' . CRLF |
413 . 'Foo: bar2' . CRLF | 436 . 'Foo: bar2' . CRLF |
414 . 'Host: localhost' . CRLF . CRLF | 437 . 'Host: localhost' . CRLF . CRLF |
415 ), qr/foo: bar1,bar2/, 'r.headersIn duplicate generic'); | 438 ), qr/foo: bar1,bar2/, 'r.headersIn duplicate generic'); |
416 | 439 |
440 like(http( | |
441 'GET /raw_hdr_in?filter=foo HTTP/1.0' . CRLF | |
442 . 'foo: bar1' . CRLF | |
443 . 'Foo: bar2' . CRLF | |
444 . 'Host: localhost' . CRLF . CRLF | |
445 ), qr/raw: bar1|bar2/, 'r.rawHeadersIn'); | |
446 | |
447 like(http_get('/raw_hdr_out?filter=a'), qr/raw: foo|bar/, 'r.rawHeadersOut'); | |
448 | |
417 } | 449 } |
418 | 450 |
419 like(http( | 451 like(http( |
420 'GET /hdr_sorted_keys?in=1 HTTP/1.0' . CRLF | 452 'GET /hdr_sorted_keys?in=1 HTTP/1.0' . CRLF |
421 . 'Cookie: foo1' . CRLF | 453 . 'Cookie: foo1' . CRLF |