]> git.kaiwu.me - nginx.git/commitdiff
Clear old Location header (if any) while adding a new one.
authorMaxim Dounin <mdounin@mdounin.ru>
Wed, 12 Oct 2011 13:28:03 +0000 (13:28 +0000)
committerMaxim Dounin <mdounin@mdounin.ru>
Wed, 12 Oct 2011 13:28:03 +0000 (13:28 +0000)
This prevents incorrect behaviour when another redirect is issued within
error_page 302 handler.

src/http/modules/ngx_http_static_module.c
src/http/ngx_http_core_module.c
src/http/ngx_http_core_module.h
src/http/ngx_http_script.c
src/http/ngx_http_special_response.c

index 57b5130d4f9351a61ee189c854c275d85debb21a..cea050a948a8da8ba54efaff81000deea50a7e55 100644 (file)
@@ -139,6 +139,8 @@ ngx_http_static_handler(ngx_http_request_t *r)
 
         ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http dir");
 
+        ngx_http_clear_location(r);
+
         r->headers_out.location = ngx_palloc(r->pool, sizeof(ngx_table_elt_t));
         if (r->headers_out.location == NULL) {
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
index 22f5bdff24433c7c2599a21da1a855f7a55db958..b9437623689624978828ac8a12e776e8fae508b4 100644 (file)
@@ -983,6 +983,8 @@ ngx_http_core_find_config_phase(ngx_http_request_t *r,
     }
 
     if (rc == NGX_DONE) {
+        ngx_http_clear_location(r);
+
         r->headers_out.location = ngx_list_push(&r->headers_out.headers);
         if (r->headers_out.location == NULL) {
             ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
@@ -1796,6 +1798,8 @@ ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status,
 
     if (status >= NGX_HTTP_MOVED_PERMANENTLY && status <= NGX_HTTP_SEE_OTHER) {
 
+        ngx_http_clear_location(r);
+
         r->headers_out.location = ngx_list_push(&r->headers_out.headers);
         if (r->headers_out.location == NULL) {
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
index df20b5d3a115cafd21cd84b198e404604a6db810..d2764fe0d2612b891535beb87cec9561d41ec48c 100644 (file)
@@ -529,5 +529,12 @@ extern ngx_str_t  ngx_http_core_get_method;
         r->headers_out.last_modified = NULL;                                  \
     }
 
+#define ngx_http_clear_location(r)                                            \
+                                                                              \
+    if (r->headers_out.location) {                                            \
+        r->headers_out.location->hash = 0;                                    \
+        r->headers_out.location = NULL;                                       \
+    }
+
 
 #endif /* _NGX_HTTP_CORE_H_INCLUDED_ */
index a703f0837898bb23c22aa3874ebfe1d009187948..6d81b4435c79c52194627c0f299b4e3d36f5d64d 100644 (file)
@@ -1106,6 +1106,8 @@ ngx_http_script_regex_end_code(ngx_http_script_engine_t *e)
                           "rewritten redirect: \"%V\"", &e->buf);
         }
 
+        ngx_http_clear_location(r);
+
         r->headers_out.location = ngx_list_push(&r->headers_out.headers);
         if (r->headers_out.location == NULL) {
             e->ip = ngx_http_script_exit;
index ea0378e4e3f8cf9a6ce21fef73226c5ef4ba0352..d30b781e5a5a84f90525d825e1b40e67430be562 100644 (file)
@@ -582,6 +582,8 @@ ngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)
     ngx_str_set(&location->key, "Location");
     location->value = uri;
 
+    ngx_http_clear_location(r);
+
     r->headers_out.location = location;
 
     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);