@@ -195,6 +195,7 @@ ngx_http_lua_ngx_redirect(lua_State *L)
195195 u_char * p ;
196196 u_char * uri ;
197197 size_t len ;
198+ ngx_table_elt_t * h ;
198199 ngx_http_request_t * r ;
199200
200201 n = lua_gettop (L );
@@ -246,23 +247,23 @@ ngx_http_lua_ngx_redirect(lua_State *L)
246247
247248 ngx_memcpy (uri , p , len );
248249
249- r -> headers_out . location = ngx_list_push (& r -> headers_out .headers );
250- if (r -> headers_out . location == NULL ) {
250+ h = ngx_list_push (& r -> headers_out .headers );
251+ if (h == NULL ) {
251252 return luaL_error (L , "no memory" );
252253 }
253254
254- r -> headers_out . location -> hash = ngx_http_lua_location_hash ;
255+ h -> hash = ngx_http_lua_location_hash ;
255256
256257#if 0
257258 dd ("location hash: %lu == %lu" ,
258- (unsigned long ) r -> headers_out . location -> hash ,
259+ (unsigned long ) h -> hash ,
259260 (unsigned long ) ngx_hash_key_lc ((u_char * ) "Location" ,
260261 sizeof ("Location" ) - 1 ));
261262#endif
262263
263- r -> headers_out . location -> value .len = len ;
264- r -> headers_out . location -> value .data = uri ;
265- ngx_str_set (& r -> headers_out . location -> key , "Location" );
264+ h -> value .len = len ;
265+ h -> value .data = uri ;
266+ ngx_str_set (& h -> key , "Location" );
266267
267268 r -> headers_out .status = rc ;
268269
@@ -271,7 +272,16 @@ ngx_http_lua_ngx_redirect(lua_State *L)
271272
272273 ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
273274 "lua redirect to \"%V\" with code %i" ,
274- & r -> headers_out .location -> value , ctx -> exit_code );
275+ & h -> value , ctx -> exit_code );
276+
277+ if (len && uri [0 ] != '/' ) {
278+ r -> headers_out .location = h ;
279+ }
280+
281+ /*
282+ * we do not set r->headers_out.location here to avoid the handling
283+ * the local redirects without a host name by ngx_http_header_filter()
284+ */
275285
276286 return lua_yield (L , 0 );
277287}
0 commit comments