@@ -2141,3 +2141,88 @@ hi
21412141-- - error_log
21422142my Content-Length: 8589934591
21432143upstream prematurely closed connection while sending to client
2144+
2145+
2146+
2147+ === TEST 95 : Expose the ' Last-Modified' response header as ngx. header[" Last-Modified" ]
2148+ -- - config
2149+ location / a. txt {
2150+ header_filter_by_lua_block {
2151+ local last_modified = ngx. header[" Last-Modified" ]
2152+ if last_modified == nil then
2153+ ngx. log (ngx. ERR, " can not get lasted modified" )
2154+ ngx. exit(500 )
2155+ return
2156+ end
2157+
2158+ local last_mod = ngx. parse_http_time(last_modified)
2159+ local age = ngx. time () - last_mod
2160+ ngx. header[" Age" ] = age
2161+ }
2162+ }
2163+ -- - user_files
2164+ >>> a. txt
2165+ Foo
2166+ -- - request
2167+ GET / a. txt
2168+ -- - raw_response_headers_like chomp
2169+ Age: \d\r\n
2170+ -- - no_error_log
2171+ [error]
2172+
2173+
2174+
2175+ === TEST 96 : ' Last-Modified' from upstream
2176+ -- - config
2177+ location / test/ {
2178+ proxy_pass http: // 127.0 . 0. 1: $ server_port / ;
2179+
2180+ header_filter_by_lua_block {
2181+ local last_modified = ngx. header[" Last-Modified" ]
2182+ if last_modified == nil then
2183+ ngx. log (ngx. ERR, " can not get lasted modified" )
2184+ ngx. exit(500 )
2185+ return
2186+ end
2187+
2188+ local last_mod = ngx. parse_http_time(last_modified)
2189+ local age = ngx. time () - last_mod
2190+ ngx. header[" Age" ] = age
2191+ }
2192+ }
2193+
2194+ -- - user_files
2195+ >>> a. txt
2196+ Foo
2197+ -- - request
2198+ GET / test/ a. txt
2199+ -- - raw_response_headers_like chomp
2200+ Age: \d\r\n
2201+ -- - no_error_log
2202+ [error]
2203+
2204+
2205+
2206+ === TEST 97 : ' Last-Modified' does not exist
2207+ -- - config
2208+ location / test {
2209+ header_filter_by_lua_block {
2210+ local last_modified = ngx. header[" Last-Modified" ]
2211+ if last_modified == nil then
2212+ ngx. log (ngx. INFO, " Last-Modified is nil as expected" )
2213+ return
2214+ end
2215+
2216+ ngx. log (ngx. ERR, " Last-Modified expected to be nil, but got " , last_modified)
2217+ }
2218+
2219+ content_by_lua_block {
2220+ ngx. say (" Hello World" )
2221+ }
2222+ }
2223+ -- - request
2224+ GET / test
2225+ -- - response_body
2226+ Hello World
2227+ -- - no_error_log
2228+ [error]
0 commit comments