From f33ac9d2e312024f96f3f2a860f3970ef894eadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Fri, 5 Nov 2010 14:58:42 +0800 Subject: [PATCH] now we allow overriding multi-value headers. --- README.markdown | 17 ++++++++++- src/ngx_http_lua_headers.c | 3 +- t/016-headers.t | 58 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index f702aa78..44041878 100644 --- a/README.markdown +++ b/README.markdown @@ -289,12 +289,27 @@ Will yield in the response headers. Only array-like tables are accepted. +Note that, for those standard headers that only accepts a single value, like Content-Type, only the last element +in the (array) table will take effect. So + + ngx.header.content_type = {'a', 'b'} + +is equivalent to + + ngx.header.content_type = 'b' + Setting a slot to nil effectively removes it from the response headers: ngx.header["X-My-Header"] = nil; +same does assigning an empty table: + + ngx.header["X-My-Header"] = {}; + +Reading values from ngx.header.HEADER is not implemented yet. + ngx.exec(uri, args) ----------- +------------------- Does an internal redirect to uri with args. diff --git a/src/ngx_http_lua_headers.c b/src/ngx_http_lua_headers.c index e38d33dc..318c10af 100644 --- a/src/ngx_http_lua_headers.c +++ b/src/ngx_http_lua_headers.c @@ -153,7 +153,8 @@ ngx_http_set_header_helper(ngx_http_request_t *r, ngx_http_lua_header_val_t *hv, *output_header = &h[i]; } - return NGX_OK; + /* return NGX_OK; */ + matched = 1; } } diff --git a/t/016-headers.t b/t/016-headers.t index 204fca52..9ebb27bf 100644 --- a/t/016-headers.t +++ b/t/016-headers.t @@ -105,7 +105,7 @@ Hello -=== TEST 6: set response content-type header +=== TEST 6: set multi response content-type header --- config location /read { content_by_lua ' @@ -122,7 +122,7 @@ Hello -=== TEST 6: set response content-type header +=== TEST 7: set response content-type header --- config location /read { content_by_lua ' @@ -137,3 +137,57 @@ Content-Type: bc --- response_body Hello + + +=== TEST 8: set multi response content-type header and clears it +--- config + location /read { + content_by_lua ' + ngx.header["X-Foo"] = {"a", "bc"} + ngx.header["X-Foo"] = {} + ngx.say("Hello") + '; + } +--- request +GET /read +--- response_headers +!X-Foo +--- response_body +Hello + + + +=== TEST 9: set multi response content-type header and clears it +--- config + location /read { + content_by_lua ' + ngx.header["X-Foo"] = {"a", "bc"} + ngx.header["X-Foo"] = nil + ngx.say("Hello") + '; + } +--- request +GET /read +--- response_headers +!X-Foo +--- response_body +Hello + + + +=== TEST 10: set multi response content-type header (multiple times) +--- config + location /read { + content_by_lua ' + ngx.header["X-Foo"] = {"a", "bc"} + ngx.header["X-Foo"] = {"a", "abc"} + ngx.say("Hello") + '; + } +--- request +GET /read +--- raw_response_headers_like chomp +X-Foo: a\r\n.*?X-Foo: abc$ +--- response_body +Hello +