]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Keep ICAP connection persistent after an OPTIONS response if possible.
authorAlex Rousskov <rousskov@measurement-factory.com>
Sun, 12 Sep 2010 21:58:38 +0000 (15:58 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sun, 12 Sep 2010 21:58:38 +0000 (15:58 -0600)
Old OptXact code used Xaction::doneReading() which was only true at EOF.
Thus, closeConnection() was thinking we are still reading (i.e., not
doneWithIo) at the end of the transaction and force-closed the connection.

New OptXact implements its own doneReading() which returns true at EOF and
when we read the entire response. Since we cannot parse OPTIONS body and
do not know where it ends, OPTIONS responses with bodies still result in
connection closure. We should not be getting any, but there are broken ICAP
servers that do send them. Hopefully, they all use Encapsulated: opt-body.

src/adaptation/icap/OptXact.cc
src/adaptation/icap/OptXact.h

index be06693e0189614da9c46580603b44ff76d001e4..b6f0af6f97fc8058dfe28eb8d4ec18bfb28bc82e 100644 (file)
@@ -19,7 +19,8 @@ CBDATA_NAMESPACED_CLASS_INIT(Adaptation::Icap, OptXactLauncher);
 
 Adaptation::Icap::OptXact::OptXact(Adaptation::Icap::ServiceRep::Pointer &aService):
         AsyncJob("Adaptation::Icap::OptXact"),
-        Adaptation::Icap::Xaction("Adaptation::Icap::OptXact", aService)
+        Adaptation::Icap::Xaction("Adaptation::Icap::OptXact", aService),
+        readAll(false)
 {
 }
 
@@ -69,6 +70,13 @@ void Adaptation::Icap::OptXact::handleCommWrote(size_t size)
 void Adaptation::Icap::OptXact::handleCommRead(size_t)
 {
     if (parseResponse()) {
+        Must(icapReply != NULL);
+        // We read everything if there is no response body. If there is a body,
+        // we cannot parse it because we do not support any opt-body-types, so
+        // we leave readAll false which forces connection closure.
+        readAll = !icapReply->header.getByNameListMember("Encapsulated",
+            "opt-body", ',').size();
+        debugs(93, 7, HERE << "readAll=" << readAll);
         icap_tio_finish = current_time;
         setOutcome(xoOpt);
         sendAnswer(icapReply);
index 0fee9a78cc9f9c05738ef750e16bfe8300e40c4d..d59fd28a5dd9ec6520a0ec05dce5891005813851 100644 (file)
@@ -63,11 +63,15 @@ protected:
     bool parseResponse();
 
     void startReading();
+    virtual bool doneReading() const { return commEof || readAll; }
 
     virtual void swanSong();
 
 private:
     virtual void finalizeLogInfo();
+
+    bool readAll; ///< read the entire OPTIONS response
+
     CBDATA_CLASS2(OptXact);
 };