Skip to content

Commit 249c918

Browse files
committed
Tests: added js headers test for multiple special headers set.
1 parent cb3d0c0 commit 249c918

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

js_headers.t

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ http {
131131
location /hdr_sorted_keys {
132132
js_content test.hdr_sorted_keys;
133133
}
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;
147+
}
134148
}
135149
}
136150
@@ -350,17 +364,50 @@ $t->write_file('test.js', <<EOF);
350364
r.finish();
351365
}
352366
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+
353399
export default {njs:test_njs, content_length, content_length_arr,
354400
content_length_keys, content_type, content_type_arr,
355401
content_encoding, content_encoding_arr, headers_list,
356402
hdr_in, raw_hdr_in, hdr_sorted_keys, foo_in, ifoo_in,
357403
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};
359406
360407
361408
EOF
362409

363-
$t->try_run('no njs')->plan(39);
410+
$t->try_run('no njs')->plan(42);
364411

365412
###############################################################################
366413

@@ -495,4 +542,21 @@ like(http(
495542
. 'Host: localhost' . CRLF . CRLF
496543
), qr/a,b,c/, 'r.headersOut sorted keys');
497544

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+
498562
###############################################################################

0 commit comments

Comments
 (0)