# HG changeset patch # User Dmitry Volyntsev # Date 1571157387 -10800 # Node ID b6699ffd9ddded807b1a9187b893125bd21cd992 # Parent 9521130f6f222a20f042ef720855b3f3f7baa3ae Tests: added Cookie and X-Forwarded-For r.headersIn tests. diff --git a/js_headers.t b/js_headers.t --- a/js_headers.t +++ b/js_headers.t @@ -12,6 +12,8 @@ use strict; use Test::More; +use Socket qw/ CRLF /; + BEGIN { use FindBin; chdir($FindBin::Bin); } use lib 'lib'; @@ -35,8 +37,8 @@ events { http { %%TEST_GLOBALS_HTTP%% - js_set $test_hdr_in test_hdr_in; - js_set $test_ihdr_in test_ihdr_in; + js_set $test_foo_in test_foo_in; + js_set $test_ifoo_in test_ifoo_in; js_include test.js; @@ -67,12 +69,16 @@ http { js_content headers_list; } - location /hdr_in { - return 200 $test_hdr_in; + location /foo_in { + return 200 $test_foo_in; } - location /ihdr_in { - return 200 $test_ihdr_in; + location /ifoo_in { + return 200 $test_ifoo_in; + } + + location /hdr_in { + js_content hdr_in; } location /hdr_out { @@ -136,11 +142,20 @@ EOF r.return(200, out); } - function test_hdr_in(r) { + function hdr_in(r) { + var s = '', h; + for (h in r.headersIn) { + s += `\${h.toLowerCase()}: \${r.headersIn[h]}\n`; + } + + r.return(200, s); + } + + function test_foo_in(r) { return 'hdr=' + r.headersIn.foo; } - function test_ihdr_in(r) { + function test_ifoo_in(r) { var s = '', h; for (h in r.headersIn) { if (h.substr(0, 3) == 'foo') { @@ -181,7 +196,7 @@ EOF EOF -$t->try_run('no njs')->plan(12); +$t->try_run('no njs')->plan(16); ############################################################################### @@ -203,4 +218,37 @@ 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'); +like(http( + 'GET /hdr_in HTTP/1.0' . CRLF + . 'Cookie: foo' . CRLF + . 'Host: localhost' . CRLF . CRLF +), qr/cookie: foo/, 'r.headersIn cookie'); + +like(http( + 'GET /hdr_in HTTP/1.0' . CRLF + . 'X-Forwarded-For: foo' . CRLF + . 'Host: localhost' . CRLF . CRLF +), qr/x-forwarded-for: foo/, 'r.headersIn xff'); + + +TODO: { +local $TODO = 'not yet' + unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.6'; + +like(http( + 'GET /hdr_in HTTP/1.0' . CRLF + . 'Cookie: foo1' . CRLF + . 'Cookie: foo2' . CRLF + . 'Host: localhost' . CRLF . CRLF +), qr/cookie: foo1; foo2/, 'r.headersIn cookie2'); + +like(http( + 'GET /hdr_in HTTP/1.0' . CRLF + . 'X-Forwarded-For: foo1' . CRLF + . 'X-Forwarded-For: foo2' . CRLF + . 'Host: localhost' . CRLF . CRLF +), qr/x-forwarded-for: foo1, foo2/, 'r.headersIn xff2'); + +} + ###############################################################################