]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Set Content-Language and Vary headers on negotiated errors
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 13 Sep 2008 09:18:50 +0000 (21:18 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 13 Sep 2008 09:18:50 +0000 (21:18 +1200)
It's also polite to send the proper Content-Language.
Error page language-negotiation requires us to send the Vary header.

src/errorpage.cc

index 4598566f7b71de9e7eca9467898772056ed5fa0f..e057a1313f104ea05dbaede09897d55298ee2142 100644 (file)
@@ -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.");
     }