comparison js_headers.t @ 1775:eacfd2b64b71

Tests: added js headers test for multiple special headers set.
author Dmitry Volyntsev <xeioex@nginx.com>
date Wed, 06 Jul 2022 15:51:40 -0700
parents 3f9b25f36e19
children f89770df737a
comparison
equal deleted inserted replaced
1774:5a625ce0de34 1775:eacfd2b64b71
128 js_content test.ihdr_out; 128 js_content test.ihdr_out;
129 } 129 }
130 130
131 location /hdr_sorted_keys { 131 location /hdr_sorted_keys {
132 js_content test.hdr_sorted_keys; 132 js_content test.hdr_sorted_keys;
133 }
134
135 location /hdr_out_special_set {
136 js_content test.hdr_out_special_set;
137 }
138
139 location /copy_subrequest_hdrs {
140 js_content test.copy_subrequest_hdrs;
141 }
142
143 location = /subrequest {
144 internal;
145
146 js_content test.subrequest;
133 } 147 }
134 } 148 }
135 } 149 }
136 150
137 EOF 151 EOF
348 r.sendHeader(); 362 r.sendHeader();
349 r.send(s); 363 r.send(s);
350 r.finish(); 364 r.finish();
351 } 365 }
352 366
367 function hdr_out_special_set(r) {
368 r.headersOut['Foo'] = "xxx";
369 r.headersOut['Content-Encoding'] = 'abc';
370
371 let ce = r.headersOut['Content-Encoding'];
372 r.return(200, `CE: \${ce}`);
373 }
374
375 async function copy_subrequest_hdrs(r) {
376 let resp = await r.subrequest("/subrequest");
377
378 for (const h in resp.headersOut) {
379 r.headersOut[h] = resp.headersOut[h];
380 }
381
382 r.return(200, resp.responseBody);
383 }
384
385 function subrequest(r) {
386 r.headersOut['A'] = 'a';
387 r.headersOut['Content-Encoding'] = 'ce';
388 r.headersOut['B'] = 'b';
389 r.headersOut['C'] = 'c';
390 r.headersOut['D'] = 'd';
391 r.headersOut['Set-Cookie'] = ['A', 'BB'];
392 r.headersOut['Content-Length'] = 3;
393 r.headersOut['Content-Type'] = 'ct';
394 r.sendHeader();
395 r.send('XXX');
396 r.finish();
397 }
398
353 export default {njs:test_njs, content_length, content_length_arr, 399 export default {njs:test_njs, content_length, content_length_arr,
354 content_length_keys, content_type, content_type_arr, 400 content_length_keys, content_type, content_type_arr,
355 content_encoding, content_encoding_arr, headers_list, 401 content_encoding, content_encoding_arr, headers_list,
356 hdr_in, raw_hdr_in, hdr_sorted_keys, foo_in, ifoo_in, 402 hdr_in, raw_hdr_in, hdr_sorted_keys, foo_in, ifoo_in,
357 hdr_out, raw_hdr_out, hdr_out_array, hdr_out_single, 403 hdr_out, raw_hdr_out, hdr_out_array, hdr_out_single,
358 hdr_out_set_cookie, ihdr_out}; 404 hdr_out_set_cookie, ihdr_out, hdr_out_special_set,
405 copy_subrequest_hdrs, subrequest};
359 406
360 407
361 EOF 408 EOF
362 409
363 $t->try_run('no njs')->plan(39); 410 $t->try_run('no njs')->plan(42);
364 411
365 ############################################################################### 412 ###############################################################################
366 413
367 like(http_get('/content_length'), qr/Content-Length: 3/, 414 like(http_get('/content_length'), qr/Content-Length: 3/,
368 'set Content-Length'); 415 'set Content-Length');
493 like(http( 540 like(http(
494 'GET /hdr_sorted_keys HTTP/1.0' . CRLF 541 'GET /hdr_sorted_keys HTTP/1.0' . CRLF
495 . 'Host: localhost' . CRLF . CRLF 542 . 'Host: localhost' . CRLF . CRLF
496 ), qr/a,b,c/, 'r.headersOut sorted keys'); 543 ), qr/a,b,c/, 'r.headersOut sorted keys');
497 544
545 TODO: {
546 local $TODO = 'not yet'
547 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.6';
548
549 like(http_get('/hdr_out_special_set'), qr/CE: abc/,
550 'r.headerOut special set');
551
552 like(http_get('/copy_subrequest_hdrs'),
553 qr/A: a.*B: b.*C: c.*D: d.*Set-Cookie: A.*Set-Cookie: BB/s,
554 'subrequest copy');
555
556 like(http_get('/copy_subrequest_hdrs'),
557 qr/Content-Type: ct.*Content-Encoding: ce.*Content-Length: 3/s,
558 'subrequest copy special');
559
560 }
561
498 ############################################################################### 562 ###############################################################################