# HG changeset patch # User Dmitry Volyntsev # Date 1587471151 0 # Node ID c1d167a13c24dd8a34a8e733937faad87207c777 # Parent b4f5289871468c3aab73017a1b8b96446e800fd8 Tests: added js tests for multi-values headers. diff --git a/js_headers.t b/js_headers.t --- a/js_headers.t +++ b/js_headers.t @@ -54,6 +54,14 @@ http { js_content content_length; } + location /content_length_arr { + js_content content_length_arr; + } + + location /content_length_keys { + js_content content_length_keys; + } + location /content_type { charset windows-1251; @@ -61,10 +69,21 @@ http { js_content content_type; } + location /content_type_arr { + charset windows-1251; + + default_type text/plain; + js_content content_type_arr; + } + location /content_encoding { js_content content_encoding; } + location /content_encoding_arr { + js_content content_encoding_arr; + } + location /headers_list { js_content headers_list; } @@ -85,6 +104,18 @@ http { js_content hdr_out; } + location /hdr_out_array { + js_content hdr_out_array; + } + + location /hdr_out_set_cookie { + js_content hdr_out_set_cookie; + } + + location /hdr_out_single { + js_content hdr_out_single; + } + location /ihdr_out { js_content ihdr_out; } @@ -112,6 +143,21 @@ EOF r.finish(); } + function content_length_arr(r) { + r.headersOut['Content-Length'] = [5]; + r.headersOut['Content-Length'] = []; + r.headersOut['Content-Length'] = [4,3]; + r.sendHeader(); + r.send('XXX'); + r.finish(); + } + + function content_length_keys(r) { + r.headersOut['Content-Length'] = 3; + var in_keys = Object.keys(r.headersOut).some(v=>v=='Content-Length'); + r.return(200, `B:\${in_keys}`); + } + function content_type(r) { r.headersOut['Content-Type'] = 'text/xml'; r.headersOut['Content-Type'] = ''; @@ -119,6 +165,14 @@ EOF delete r.headersOut['Content-Type']; r.headersOut['Content-Type'] = 'text/xml; charset=utf-8'; r.headersOut['Content-Type'] = 'text/xml; charset="utf-8"'; + var in_keys = Object.keys(r.headersOut).some(v=>v=='Content-Type'); + r.return(200, `B:\${in_keys}`); + } + + function content_type_arr(r) { + r.headersOut['Content-Type'] = ['text/html']; + r.headersOut['Content-Type'] = []; + r.headersOut['Content-Type'] = [ 'text/xml', 'text/html']; r.return(200); } @@ -130,6 +184,13 @@ EOF r.return(200); } + function content_encoding_arr(r) { + r.headersOut['Content-Encoding'] = 'test'; + r.headersOut['Content-Encoding'] = []; + r.headersOut['Content-Encoding'] = ['test', 'gzip']; + r.return(200); + } + function headers_list(r) { for (var h in {a:1, b:2, c:3}) { r.headersOut[h] = h; @@ -195,6 +256,35 @@ EOF r.finish(); } + function hdr_out_array(r) { + if (!r.args.hidden) { + r.headersOut['Foo'] = [r.args.fOO]; + r.headersOut['Foo'] = []; + r.headersOut['Foo'] = ['bar', r.args.fOO]; + } + + if (r.args.scalar_set) { + r.headersOut['Foo'] = 'xxx'; + } + + r.return(200, `B:\${njs.dump(r.headersOut.foo)}`); + } + + function hdr_out_single(r) { + r.headersOut.ETag = ['a', 'b']; + r.return(200, `B:\${njs.dump(r.headersOut.etag)}`); + } + + function hdr_out_set_cookie(r) { + r.headersOut['Set-Cookie'] = []; + r.headersOut['Set-Cookie'] = ['a', 'b']; + delete r.headersOut['Set-Cookie']; + r.headersOut['Set-Cookie'] = 'e'; + r.headersOut['Set-Cookie'] = ['c', '', null, 'd', 'f']; + + r.return(200, `B:\${njs.dump(r.headersOut['Set-Cookie'])}`); + } + function ihdr_out(r) { r.status = 200; r.headersOut['a'] = r.args.a; @@ -213,7 +303,7 @@ EOF EOF -$t->try_run('no njs')->plan(18); +$t->try_run('no njs')->plan(34); ############################################################################### @@ -235,6 +325,44 @@ unlike(http_get('/hdr_out?bar=empty'), q unlike(http_get('/hdr_out?foo='), qr/Foo:/, 'r.headersOut no value'); unlike(http_get('/hdr_out?foo'), qr/Foo:/, 'r.headersOut no value 2'); +TODO: { +local $TODO = 'not yet' + unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.4.0'; + +like(http_get('/content_length_keys'), qr/B:true/, 'Content-Length in keys'); +like(http_get('/content_length_arr'), qr/Content-Length: 3/, + 'set Content-Length arr'); + +like(http_get('/content_type'), qr/B:true/, 'Content-Type in keys'); +like(http_get('/content_type_arr'), qr/Content-Type: text\/html/, + 'set Content-Type arr'); +like(http_get('/content_encoding_arr'), qr/Content-Encoding: gzip/, + 'set Content-Encoding arr'); + +like(http_get('/hdr_out_array?foo=12345'), qr/Foo: bar\r\nFoo: 12345/, + 'r.headersOut arr'); +like(http_get('/hdr_out_array'), qr/Foo: bar/, + 'r.headersOut arr last is empty'); +like(http_get('/hdr_out_array?foo=abc'), qr/B:bar,abc/, + 'r.headersOut get'); +like(http_get('/hdr_out_array'), qr/B:bar/, 'r.headersOut get2'); +like(http_get('/hdr_out_array?hidden=1'), qr/B:undefined/, + 'r.headersOut get3'); +like(http_get('/hdr_out_array?scalar_set=1'), qr/B:xxx/, + 'r.headersOut scalar set'); +like(http_get('/hdr_out_single'), qr/ETag: a\r\nETag: b/, + 'r.headersOut single'); +like(http_get('/hdr_out_single'), qr/B:a/, + 'r.headersOut single get'); +like(http_get('/hdr_out_set_cookie'), qr/Set-Cookie: c\r\nSet-Cookie: d/, + 'set_cookie'); +like(http_get('/hdr_out_set_cookie'), qr/B:\['c','d','f']/, + 'set_cookie2'); +unlike(http_get('/hdr_out_set_cookie'), qr/Set-Cookie: [abe]/, + 'set_cookie3'); + +} + like(http( 'GET /hdr_in HTTP/1.0' . CRLF . 'Cookie: foo' . CRLF @@ -250,7 +378,7 @@ like(http( TODO: { local $TODO = 'not yet' - unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.6'; + unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.6'; like(http( 'GET /hdr_in HTTP/1.0' . CRLF @@ -270,7 +398,7 @@ like(http( TODO: { local $TODO = 'not yet' - unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.7'; + unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.7'; like(http( 'GET /hdr_sorted_keys?in=1 HTTP/1.0' . CRLF