content-handling-errors: fall back to nginx's default handling

This change passes on non succesful status codes for pagespeed
resources and other places where we act as a content handler to
nginx. This has two benefits:
- Instead of a blank page, the user agent receives a formatted
  and (hopefully customized and informative) response.
- Header modules are able to operate on that response, which was
  requested in https://github.com/pagespeed/ngx_pagespeed/issues/612#issuecomment-58855816
This commit is contained in:
Otto van der Schaaf
2015-01-26 22:13:15 +01:00
parent 02b67b79ad
commit 3efebb7948
4 changed files with 26 additions and 1 deletions
+1
View File
@@ -116,6 +116,7 @@ class NgxBaseFetch : public AsyncFetch {
bool detached() { return detached_; }
ngx_http_request_t* request() { return request_; }
NgxBaseFetchType base_fetch_type() { return base_fetch_type_; }
private:
virtual bool HandleWrite(const StringPiece& sp, MessageHandler* handler);
+13
View File
@@ -266,6 +266,19 @@ ngx_int_t ps_base_fetch_handler(ngx_http_request_t* r) {
"ps fetch handler: %V", &r->uri);
if (!r->header_sent) {
int status_code = ctx->base_fetch->response_headers()->status_code();
bool status_ok = (status_code != 0) && (status_code < 400);
// Pass on error handling for non-success status codes to nginx for
// responses where PSOL acts as a content generator (pagespeed resource,
// ipro hit, admin pages).
// This generates nginx's default error responses, but also allows header
// modules running after us to manipulate those responses.
if (!status_ok && (ctx->base_fetch->base_fetch_type() != kHtmlTransform
&& ctx->base_fetch->base_fetch_type() != kIproLookup)) {
return status_code;
}
if (ctx->preserve_caching_headers != kDontPreserveHeaders) {
ngx_table_elt_t* header;
NgxListIterator it(&(r->headers_out.headers.part));
+10
View File
@@ -1143,6 +1143,16 @@ OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP -O /dev/null -S $URL 2>&1)
MATCHES=$(echo "$OUT" | grep -c "Server: override") || true
check [ $MATCHES -eq 1 ]
start_test Conditional cache-control header override in resource flow.
URL=http://headers.example.com/mod_pagespeed_test/
URL+=A.doesnotexist.css.pagespeed.cf.0.css
# The 404 response makes wget exit with an error code, which we ignore.
OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP -O /dev/null -S $URL 2>&1) || true
# We ignored the exit code, check if we got a 404 response.
check_from "$OUT" fgrep -qi '404'
MATCHES=$(echo "$OUT" | grep -c "Cache-Control: override") || true
check [ $MATCHES -eq 1 ]
if $USE_VALGRIND; then
# It is possible that there are still ProxyFetches outstanding
# at this point in time. Give them a few extra seconds to allow
+2 -1
View File
@@ -1192,7 +1192,8 @@ http {
pagespeed LoadFromFile "http://headers.example.com/"
"@@SERVER_ROOT@@/";
location /mod_pagespeed_test/ {
more_set_headers "Server: overriden";
more_set_headers "Server: override";
more_set_headers -s '404' 'Cache-Control: override';
}
}