]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Alex Rousskov <rousskov@measurement-factory.com>
authorAmos Jeffries <amosjeffries@squid-cache.org>
Wed, 18 Aug 2010 23:43:22 +0000 (17:43 -0600)
committerAmos Jeffries <amosjeffries@squid-cache.org>
Wed, 18 Aug 2010 23:43:22 +0000 (17:43 -0600)
Bug 3016: HTTP/1.1 compliance: default keep-alive for 1.0/1.1 clients.

aka. NTLM Authentication with Java UA + SSL Problem
Moved httpMsgIsPersistent(version, headers) to HttpMsg::persistent(void).

This move makes it clear that the logic applies only to the message being
examined and not some irrelevant information such as HTTP version supported
by Squid.

Side-effects:

 - In v3.2, Squid stops using persistent connections with HTTP/1.0 clients
   that do not send "Connection: keep-alive".

 - In v3.1, Squid starts using persistent connections with HTTP/1.1 clients
   that do not send "Connection: close".

 - HttpReply now sets HttpMsg::http_ver member. It is not clear whether
   that member was ever used for HttpReplies though.

src/HttpHeader.h
src/HttpMsg.cc
src/HttpMsg.h
src/HttpReply.cc
src/client_side.cc

index c9e3e9696b4ce1d84c12cafc67ebc9622e27ac67..6408bb2a572e3281c83bd5451214484adce20262 100644 (file)
@@ -40,7 +40,6 @@
 
 
 /* class forward declarations */
-class HttpVersion;
 class HttpHdrContRange;
 class HttpHdrCc;
 class HttpHdrSc;
@@ -278,8 +277,6 @@ private:
 extern int httpHeaderParseQuotedString (const char *start, String *val);
 SQUIDCEXTERN int httpHeaderHasByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator);
 SQUIDCEXTERN void httpHeaderUpdate(HttpHeader * old, const HttpHeader * fresh, const HttpHeaderMask * denied_mask);
-int httpMsgIsPersistent(HttpVersion const &http_ver, const HttpHeader * hdr);
-
 SQUIDCEXTERN void httpHeaderCalcMask(HttpHeaderMask * mask, http_hdr_type http_hdr_type_enums[], size_t count);
 
 #endif /* SQUID_HTTPHEADER_H */
index 15466eb7ea8fc54b11762d7ccad323bf482ca8fd..cd5d5cca89341b5f93ae6d0cfff3c3d8fdbd13f6 100644 (file)
@@ -316,11 +316,10 @@ HttpMsg::setContentLength(int64_t clen)
     content_length = clen;
 }
 
-/* returns true if connection should be "persistent"
- * after processing this message */
-int
-httpMsgIsPersistent(HttpVersion const &http_ver, const HttpHeader * hdr)
+bool
+HttpMsg::persistent() const
 {
+    const HttpHeader *hdr = &header; // XXX: diff-minimizer; remove on commit
     if ((http_ver.major >= 1) && (http_ver.minor >= 1)) {
         /*
          * for modern versions of HTTP: persistent unless there is
index a707b1c57b6559beddf21168110518edc0b35d2e..525afbdb97a256ae344f56f6fe3e92300cfe5924 100644 (file)
@@ -61,6 +61,14 @@ public:
     /// [re]sets Content-Length header and cached value
     void setContentLength(int64_t clen);
 
+    /** 
+     * \retval true  the message sender asks to keep the connection open.
+     * \retval false the message sender will close the connection.
+     *
+     * Factors other than the headers may result in connection closure.
+     */
+    bool persistent() const;
+
 public:
     HttpVersion http_ver;
 
index 123c323910a6f3eeadce29c2998f7ccb1614fe02..2dc470abe362fa73a4b88d9d45ee047829a19429 100644 (file)
@@ -377,12 +377,13 @@ HttpReply::hdrCacheInit()
 {
     HttpMsg::hdrCacheInit();
 
+    http_ver = sline.version;
     content_length = header.getInt64(HDR_CONTENT_LENGTH);
     date = header.getTime(HDR_DATE);
     last_modified = header.getTime(HDR_LAST_MODIFIED);
     surrogate_control = header.getSc();
     content_range = header.getContRange();
-    keep_alive = httpMsgIsPersistent(sline.version, &header);
+    keep_alive = persistent() ? 1 : 0;
     const char *str = header.getStr(HDR_CONTENT_TYPE);
 
     if (str)
index c722a659c204c7ef5137b1a7b291fea192ad8e49..dc3306b40b300c526458b144f48420d0cb21a6c1 100644 (file)
@@ -735,18 +735,14 @@ static void
 clientSetKeepaliveFlag(ClientHttpRequest * http)
 {
     HttpRequest *request = http->request;
-    const HttpHeader *req_hdr = &request->header;
 
     debugs(33, 3, "clientSetKeepaliveFlag: http_ver = " <<
            request->http_ver.major << "." << request->http_ver.minor);
     debugs(33, 3, "clientSetKeepaliveFlag: method = " <<
            RequestMethodStr(request->method));
 
-    /* We are HTTP/1.1 facing clients now*/
-    HttpVersion http_ver(1,1);
-
-    if (httpMsgIsPersistent(http_ver, req_hdr))
-        request->flags.proxy_keepalive = 1;
+    // TODO: move to HttpRequest::hdrCacheInit, just like HttpReply.
+    request->flags.proxy_keepalive = request->persistent() ? 1 : 0;
 }
 
 static int