From: Amos Jeffries Date: Sat, 13 Sep 2008 09:18:50 +0000 (+1200) Subject: Set Content-Language and Vary headers on negotiated errors X-Git-Tag: SQUID_3_1_0_1~45^2~24^2~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bf33a09d279fd519bf356975be6e55f955c3e2d;p=thirdparty%2Fsquid.git Set Content-Language and Vary headers on negotiated errors It's also polite to send the proper Content-Language. Error page language-negotiation requires us to send the Vary header. --- diff --git a/src/errorpage.cc b/src/errorpage.cc index 4598566f7b..e057a1313f 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -245,8 +245,9 @@ errorLoadText(const char *page_name) #endif /* test default location if failed (templates == English translation base templates) */ - if (!text) + if (!text) { text = errorTryLoadText(page_name, DEFAULT_SQUID_ERROR_DIR"/templates"); + } /* giving up if failed */ if (!text) @@ -370,6 +371,7 @@ errorCon(err_type type, http_status status, HttpRequest * request) { ErrorState *err = new ErrorState; err->page_id = type; /* has to be reset manually if needed */ + err->err_language = NULL; err->type = type; err->httpStatus = status; @@ -487,6 +489,10 @@ errorStateFree(ErrorState * err) safe_free(err->ftp.reply); AUTHUSERREQUESTUNLOCK(err->auth_user_request, "errstate"); safe_free(err->err_msg); +#if USE_ERR_LOCALES + if(err->err_language != Config.errorDefaultLanguage) +#endif + safe_free(err->err_language); cbdataFree(err); } @@ -851,14 +857,30 @@ ErrorState::BuildHttpReply() */ httpHeaderPutStrf(&rep->header, HDR_X_SQUID_ERROR, "%s %d", name, xerrno); - /* add the Content-Language header according to RFC section 14.21 */ +#if USE_ERR_LOCALES + /* + * If error page auto-negotiate is enabled in any way, send the Vary. + * RFC 2616 section 13.6 and 14.44 says MAY and SHOULD do this. + * We have even better reasons though: + * see http://wiki.squid-cache.org/KnowledgeBase/VaryNotCaching + */ + if(!Config.errorDirectory) { + /* We 'negotiated' this ONLY from the Accept-Language. */ + httpHeaderDelById(&rep->header, HDR_VARY); + httpHeaderPutStrf(&rep->header, HDR_VARY, "Accept-Language"); + } + + /* add the Content-Language header according to RFC section 14.12 */ if(err_language) { httpHeaderPutStrf(&rep->header, HDR_CONTENT_LANGUAGE, "%s", err_language); - /* TODO: do we need to modify Vary: header as well? */ } - else { + else +#endif /* USE_ERROR_LOCALES */ + { /* default templates are in English */ - httpHeaderPutStrf(&rep->header, HDR_CONTENT_LANGUAGE, "en"); + /* language is known unless error_directory override used */ + if(!Config.errorDirectory) + httpHeaderPutStrf(&rep->header, HDR_CONTENT_LANGUAGE, "en"); } httpBodySet(&rep->body, content); @@ -953,6 +975,10 @@ ErrorState::BuildContent() */ if(!m) { m = error_text[page_id]; +#if USE_ERR_LOCALES + if(!Config.errorDirectory) + err_language = Config.errorDefaultLanguage; +#endif debugs(4, 1, HERE << "No existing languages found. Fall back on default language."); }