Merge pull request #1085 from pagespeed/oschaaf-trunk-tracking-internal-redirect-crasher
Fix crasher on 404 .pagespeed. resources w/a custom location
diff --git a/src/ngx_pagespeed.cc b/src/ngx_pagespeed.cc
index 65c362a..a4490d4 100644
--- a/src/ngx_pagespeed.cc
+++ b/src/ngx_pagespeed.cc
@@ -303,6 +303,12 @@
STR_CASE_EQ_LITERAL(header->key, "Last-Modified") ||
STR_CASE_EQ_LITERAL(header->key, "Expires"))))) {
header->hash = 0;
+ if (STR_CASE_EQ_LITERAL(header->key, "Location")) {
+ // There's a possible issue with the location header, where setting
+ // the hash to 0 is not enough. See:
+ // https://github.com/nginx/nginx/blob/master/src/http/ngx_http_header_filter_module.c#L314
+ r->headers_out.location = NULL;
+ }
}
}
} else {
@@ -453,11 +459,6 @@
headers->set_status_code(r->headers_out.status);
- if (r->headers_out.location != NULL) {
- headers->Add(HttpAttributes::kLocation,
- str_to_string_piece(r->headers_out.location->value));
- }
-
// Manually copy over the content type because it's not included in
// request_->headers_out.headers.
headers->Add(HttpAttributes::kContentType,