Welcome! Log In Create A New Profile

Advanced

[PATCH 5 of 5] Clear old Location header (if any) while adding new one

Maxim Dounin
November 02, 2010 12:02AM
# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1288669817 -10800
# Node ID 24596859ecb7d152308e0e8bc5e49e3adfb49b44
# Parent 15e61ffe345655369098c613d6f99484a0c171c8
Clear old Location header (if any) while adding new one.

This prevents incorrect behaviour when another redirect is issues within
error_page 302 handler.

diff --git a/src/http/modules/ngx_http_static_module.c b/src/http/modules/ngx_http_static_module.c
--- a/src/http/modules/ngx_http_static_module.c
+++ b/src/http/modules/ngx_http_static_module.c
@@ -139,6 +139,10 @@ ngx_http_static_handler(ngx_http_request

ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http dir");

+ if (r->headers_out.location) {
+ r->headers_out.location->hash = 0;
+ }
+
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;
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -970,6 +970,10 @@ ngx_http_core_find_config_phase(ngx_http
}

if (rc == NGX_DONE) {
+ if (r->headers_out.location) {
+ r->headers_out.location->hash = 0;
+ }
+
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);
@@ -1753,6 +1757,10 @@ ngx_http_send_response(ngx_http_request_

if (status >= NGX_HTTP_MOVED_PERMANENTLY && status <= NGX_HTTP_SEE_OTHER) {

+ if (r->headers_out.location) {
+ r->headers_out.location->hash = 0;
+ }
+
r->headers_out.location = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.location == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c
--- a/src/http/ngx_http_script.c
+++ b/src/http/ngx_http_script.c
@@ -1106,6 +1106,10 @@ ngx_http_script_regex_end_code(ngx_http_
"rewritten redirect: \"%V\"", &e->buf);
}

+ if (r->headers_out.location) {
+ r->headers_out.location->hash = 0;
+ }
+
r->headers_out.location = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.location == NULL) {
e->ip = ngx_http_script_exit;
diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -570,6 +570,10 @@ ngx_http_send_error_page(ngx_http_reques
ngx_str_set(&location->key, "Location");
location->value = uri;

+ if (r->headers_out.location) {
+ r->headers_out.location->hash = 0;
+ }
+
r->headers_out.location = location;

clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH 5 of 5] Clear old Location header (if any) while adding new one

Maxim Dounin 1695 November 02, 2010 12:02AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 69
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready