# HG changeset patch # User Dmitry Volyntsev # Date 1588769537 0 # Node ID 4cc012205ac533bd531538ec3cfc4f10b34f5345 # Parent 726877fc4b0882feca8596301e30c2fb1eac17b9 Tests: added js tests for raw headers API. diff --git a/js_headers.t b/js_headers.t --- a/js_headers.t +++ b/js_headers.t @@ -100,10 +100,18 @@ http { js_content hdr_in; } + location /raw_hdr_in { + js_content raw_hdr_in; + } + location /hdr_out { js_content hdr_out; } + location /raw_hdr_out { + js_content raw_hdr_out; + } + location /hdr_out_array { js_content hdr_out_array; } @@ -216,6 +224,12 @@ EOF r.return(200, s); } + function raw_hdr_in(r) { + var filtered = r.rawHeadersIn + .filter(v=>v[0].toLowerCase() == r.args.filter); + r.return(200, 'raw:' + filtered.map(v=>v[1]).join('|')); + } + function hdr_sorted_keys(r) { var s = ''; var hdr = r.args.in ? r.headersIn : r.headersOut; @@ -256,6 +270,15 @@ EOF r.finish(); } + function raw_hdr_out(r) { + r.headersOut.a = ['foo', 'bar']; + r.headersOut.b = 'b'; + + var filtered = r.rawHeadersOut + .filter(v=>v[0].toLowerCase() == r.args.filter); + r.return(200, 'raw:' + filtered.map(v=>v[1]).join('|')); + } + function hdr_out_array(r) { if (!r.args.hidden) { r.headersOut['Foo'] = [r.args.fOO]; @@ -303,7 +326,7 @@ EOF EOF -$t->try_run('no njs')->plan(37); +$t->try_run('no njs')->plan(39); ############################################################################### @@ -414,6 +437,15 @@ like(http( . 'Host: localhost' . CRLF . CRLF ), qr/foo: bar1,bar2/, 'r.headersIn duplicate generic'); +like(http( + 'GET /raw_hdr_in?filter=foo HTTP/1.0' . CRLF + . 'foo: bar1' . CRLF + . 'Foo: bar2' . CRLF + . 'Host: localhost' . CRLF . CRLF +), qr/raw: bar1|bar2/, 'r.rawHeadersIn'); + +like(http_get('/raw_hdr_out?filter=a'), qr/raw: foo|bar/, 'r.rawHeadersOut'); + } like(http(