[MERGE] Content-Language headers

From: Amos Jeffries <squid3_at_treenet.co.nz>
Date: Sat, 13 Sep 2008 21:44:03 +1200

Adds "Content-Language" header properly if the error page language was
negotiated. Hard codes the default templates as 'en', and the squid.conf
value for soft default language of error_default_language was used.

Sets "Vary: Accept-Language" if negotiation is configured to take place
at all.

Amos

-- 
Please use Squid 2.7.STABLE4 or 3.0.STABLE9

# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: squid3_at_treenet.co.nz-20080913091850-je85s7pipse6vvv6
# target_branch: file:///src/squid/bzr/trunk/
# testament_sha1: 2db6c0b313b249ea9b3e6d0525fcb30423ce2057
# timestamp: 2008-09-13 21:34:31 +1200
# base_revision_id: squid3_at_treenet.co.nz-20080913000021-\
# er8pqy8bnou267cl
#
# Begin patch
=== modified file 'src/errorpage.cc'
--- src/errorpage.cc 2008-08-09 05:59:55 +0000
+++ src/errorpage.cc 2008-09-13 09:18:50 +0000
@@ -245,8 +245,9 @@
 #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 @@
 {
     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 @@
     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);
 }
 
@@ -850,6 +856,33 @@
          * X-CACHE-MISS entry should tell us who.
          */
         httpHeaderPutStrf(&rep->header, HDR_X_SQUID_ERROR, "%s %d", name, xerrno);
+
+#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);
+ }
+ else
+#endif /* USE_ERROR_LOCALES */
+ {
+ /* default templates are in English */
+ /* language is known unless error_directory override used */
+ if(!Config.errorDirectory)
+ httpHeaderPutStrf(&rep->header, HDR_CONTENT_LANGUAGE, "en");
+ }
+
         httpBodySet(&rep->body, content);
         /* do not memBufClean() or delete the content, it was absorbed by httpBody */
     }
@@ -912,7 +945,11 @@
                 debugs(4, 6, HERE << "Found language '" << reset << "', testing for available template in: '" << dir << "'");
                 m = errorTryLoadText( err_type_str[page_id], dir, false);
 
- if(m) break; // FOUND IT!!
+ if(m) {
+ /* store the language we found for the Content-Language reply header */
+ err_language = xstrdup(reset);
+ break;
+ }
 
 #if HAVE_GLOB
                 if( (dt - reset) == 2) {
@@ -938,6 +975,10 @@
      */
     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.");
     }
 

=== modified file 'src/errorpage.h'
--- src/errorpage.h 2008-09-10 06:00:39 +0000
+++ src/errorpage.h 2008-09-13 06:00:54 +0000
@@ -115,6 +115,7 @@
 public:
     err_type type;
     int page_id;
+ char *err_language;
     http_status httpStatus;
     AuthUserRequest *auth_user_request;
     HttpRequest *request;

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWXXg7kMACPT/gEZUQAB7////
///fpL////pgDZ6992wd7nvaAAAAA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xJ/YiqPUIv7j71LMmIul1fdXCRITjAA94iKL4
79rYARsMiZNM9tZBF5BMiXh68oJcllBwoefNkfvKRoStNTCSpCtMIMK61mU6xFn53TBzmhkCsRa3
Lm9DPIe0J0sQxwqHSnrTGxKS8U0W0VBxAMpNy1S0XC1QxS8H79XMHOhxZ92ww5QeHYmOKRL24GJ3
076aVfBtiXUTDlGWrcadyzuQ5i1YlgkJjGh6g8WUO0otvl7CHA75by6qWVCpE4GIFEiwM4DAHiiS
LBAebx0yDrmIS9gqCS9iJk/m4I9aIo4oYAgKwYZl+eKNSSROBKKEZBT87gb0eeAlSQSdkoTNLE0k
DmCqRhkVih0ezb1xB+TTu8krfbKdwL6xVRRGIhkN77xHsXLz/OZcRRWjB57/E0gI6CI0pJIRFHxZ
pe26U7GM3bge9/SaH6YSHbKaKKCUwoJRCkhTCmQN1AsAN7nOmrMMh2PRdZoDVJQiuftUVeiqLCOx
zmEkXCN0T5teRQ5nNHIUA/a0TOkUwTiEoTobhpMQxQM6ZAglIyn3JHmIv4BNcgSmFbt5OJe6YGi6
huhwBHGHvBJelHBQrlOznH0hQMwxF4hxiEdklVXNaUTveWgfaNxdpvxn+gKionXCEM/bKmxgyKqT
gHuOeqOLF6GvkDrfrHRBkesE4egPJgQmoTwkGd4BLXwqpByA7Qi3bW0JW2Du0CQHSm90QIen01/4
u5IpwoSDrwdyGA==
Received on Sat Sep 13 2008 - 09:44:14 MDT

This archive was generated by hypermail 2.2.0 : Mon Sep 22 2008 - 12:00:04 MDT