Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/ngx_http_lua_headers_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ ngx_http_lua_get_output_header(lua_State *L, ngx_http_request_t *r,
ngx_uint_t i;
unsigned found;

u_char buf[sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1];

dd("looking for response header \"%.*s\"", (int) key->len, key->data);

switch (key->len) {
Expand All @@ -560,6 +562,17 @@ ngx_http_lua_get_output_header(lua_State *L, ngx_http_request_t *r,

break;

case 13:
if (r->headers_out.last_modified_time >= 0
&& ngx_strncasecmp(key->data, (u_char *) "Last-Modified", 13) == 0)
{
(void) ngx_http_time(buf, r->headers_out.last_modified_time);
lua_pushlstring(L, (char *) buf, sizeof(buf));
return 1;
}

break;

default:
break;
}
Expand Down
21 changes: 20 additions & 1 deletion t/016-resp-header.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Test::Nginx::Socket::Lua;

repeat_each(2);

plan tests => repeat_each() * (blocks() * 3 + 46);
plan tests => repeat_each() * (blocks() * 3 + 45);

#no_diff();
no_long_string();
Expand Down Expand Up @@ -1699,3 +1699,22 @@ found 3 resp headers
--- no_error_log
[error]
lua exceeding response header limit



=== TEST 76: Expose the 'Last-Modified' response header as ngx.header["Last-Modified"]
--- config
location /read {
header_filter_by_lua '
local last_mod = ngx.parse_http_time(ngx.header["Last-Modified"])
local age = ngx.time() - last_mod
ngx.header["Age"] = age
';
}
--- user_files
>>> read/test
Foo
--- request
GET /read/test
--- raw_response_headers_like chomp
Age: \d\r\n