]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Finish forward-porting HTCP enhancements from squid 2.HEAD.
authorBenno Rice <benno@squid-cache.org>
Thu, 18 Sep 2008 02:55:19 +0000 (12:55 +1000)
committerBenno Rice <benno@squid-cache.org>
Thu, 18 Sep 2008 02:55:19 +0000 (12:55 +1000)
- Fix purgeEntriesByUrl call.
- Add logic needed to send HTCP CLR request.
- Add logic needed to send HTCP CLR requests to all configured neighbors.
- Wire in calls to send CLR requests to neighbors in appropriate places.
- Use a reference to the HttpRequestMethod rather than a pointer.
- Various cleanups.

src/Server.cc
src/client_side_reply.cc
src/htcp.cc
src/htcp.h
src/http.cc
src/neighbors.cc
src/protos.h

index 830b55217c828ce44e64625dd2aad64e04ef164c..deae0318439de18937f304446ab9206cc12b3bfd 100644 (file)
@@ -426,7 +426,7 @@ purgeEntriesByHeader(HttpRequest *req, const char *reqUrl, HttpMsg *rep, http_hd
         return;
     }
     
-    purgeEntriesByUrl(hdrUrl);
+    purgeEntriesByUrl(req, hdrUrl);
     
     if (absUrl != NULL) {
         safe_free(absUrl);
index d91ea182d63abbcbe1431b878340be5de12e2d47..b7031641be2b4406c2d8385d36b84a6554345168 100644 (file)
@@ -723,17 +723,30 @@ clientReplyContext::purgeRequestFindObjectToPurge()
 void
 purgeEntriesByUrl(HttpRequest * req, const char *url)
 {
+#if USE_HTCP
+    bool get_or_head_sent = false;
+#endif
+    
     for (HttpRequestMethod m(METHOD_NONE); m != METHOD_ENUM_END; ++m) {
         if (m.isCacheble()) {
             if (StoreEntry *entry = storeGetPublic(url, m)) {
                 debugs(88, 5, "purging " << RequestMethodStr(m) << ' ' << url);
-                entry->release();
 #if USE_HTCP
-                neighborsHtcpClear(NULL, url, req, &m, HTCP_CLR_INVALIDATION);
+                neighborsHtcpClear(entry, url, req, m, HTCP_CLR_INVALIDATION);
+                if (m == METHOD_GET || m == METHOD_HEAD) {
+                    get_or_head_sent = true;
+                }
 #endif
+                entry->release();
             }
         }
     }
+
+#if USE_HTCP
+    if (!get_or_head_sent) {
+        neighborsHtcpClear(NULL, url, req, HttpRequestMethod(METHOD_GET), HTCP_CLR_INVALIDATION);
+    }
+#endif
 }
 
 void 
@@ -854,6 +867,9 @@ clientReplyContext::purgeDoPurgeGet(StoreEntry *newEntry)
     if (!newEntry->isNull()) {
         /* Release the cached URI */
         debugs(88, 4, "clientPurgeRequest: GET '" << newEntry->url() << "'" );
+#if USE_HTCP
+        neighborsHtcpClear(newEntry, NULL, http->request, HttpRequestMethod(METHOD_GET), HTCP_CLR_PURGE);
+#endif
         newEntry->release();
         purgeStatus = HTTP_OK;
     }
@@ -867,6 +883,9 @@ clientReplyContext::purgeDoPurgeHead(StoreEntry *newEntry)
 {
     if (newEntry && !newEntry->isNull()) {
         debugs(88, 4, "clientPurgeRequest: HEAD '" << newEntry->url() << "'" );
+#if USE_HTCP
+        neighborsHtcpClear(newEntry, NULL, http->request, HttpRequestMethod(METHOD_HEAD), HTCP_CLR_PURGE);
+#endif
         newEntry->release();
         purgeStatus = HTTP_OK;
     }
@@ -879,6 +898,9 @@ clientReplyContext::purgeDoPurgeHead(StoreEntry *newEntry)
 
         if (entry) {
             debugs(88, 4, "clientPurgeRequest: Vary GET '" << entry->url() << "'" );
+#if USE_HTCP
+            neighborsHtcpClear(entry, NULL, http->request, HttpRequestMethod(METHOD_GET), HTCP_CLR_PURGE);
+#endif
             entry->release();
             purgeStatus = HTTP_OK;
         }
@@ -887,6 +909,9 @@ clientReplyContext::purgeDoPurgeHead(StoreEntry *newEntry)
 
         if (entry) {
             debugs(88, 4, "clientPurgeRequest: Vary HEAD '" << entry->url() << "'" );
+#if USE_HTCP
+            neighborsHtcpClear(entry, NULL, http->request, HttpRequestMethod(METHOD_HEAD), HTCP_CLR_PURGE);
+#endif
             entry->release();
             purgeStatus = HTTP_OK;
         }
index b2108c2069a3de4abcb0a0eb4f202d7aeb5a168b..f09f94418f14012cb516873f809c534285bd0b94 100644 (file)
@@ -1578,7 +1578,7 @@ htcpQuery(StoreEntry * e, HttpRequest * req, peer * p)
 }
 
 void
-htcpClear(StoreEntry * e, const char *uri, HttpRequest * req, HttpRequestMethod * method, peer * p, htcp_clr_reason reason)
+htcpClear(StoreEntry * e, const char *uri, HttpRequest * req, const HttpRequestMethod &method, peer * p, htcp_clr_reason reason)
 {
     static char pkt[8192];
     ssize_t pktlen;
@@ -1627,6 +1627,9 @@ htcpClear(StoreEntry * e, const char *uri, HttpRequest * req, HttpRequestMethod
         hdr.clean();
         packerClean(&pa);
        stuff.S.req_hdrs = mb.buf;
+        debug(31, 1) ("htcpClear: headers: %s\n", stuff.S.req_hdrs);
+    } else {
+        stuff.S.req_hdrs = NULL;
     }
     pktlen = htcpBuildPacket(pkt, sizeof(pkt), &stuff);
     if (reason != HTCP_CLR_INVALIDATION) {
@@ -1636,7 +1639,7 @@ htcpClear(StoreEntry * e, const char *uri, HttpRequest * req, HttpRequestMethod
        xfree(stuff.S.uri);
     }
     if (!pktlen) {
-       debug(31, 1) ("htcpQuery: htcpBuildPacket() failed\n");
+       debug(31, 1) ("htcpClear: htcpBuildPacket() failed\n");
        return;
     }
     
index ce8885828802281b5dbcef34328a9462914be839..c0f02c0f9dce8c6513032389dfc04d9ec93acfab 100644 (file)
@@ -70,7 +70,7 @@ SQUIDCEXTERN void htcpInit(void);
 SQUIDCEXTERN void htcpQuery(StoreEntry * e, HttpRequest * req, peer * p);
 
 /// \ingroup ServerProtocolHTCP
-SQUIDCEXTERN void htcpClear(StoreEntry * e, const char *uri, HttpRequest * req, HttpRequestMethod * method, peer * p, htcp_clr_reason reason);
+SQUIDCEXTERN void htcpClear(StoreEntry * e, const char *uri, HttpRequest * req, const HttpRequestMethod &method, peer * p, htcp_clr_reason reason);
 
 /// \ingroup ServerProtocolHTCP
 SQUIDCEXTERN void htcpSocketShutdown(void);
index 00e1c09102d960c9a2168043f527c08dfda3269c..0db0fd268d25afeec7c691745c98a37dcefe579d 100644 (file)
@@ -275,7 +275,7 @@ httpMaybeRemovePublic(StoreEntry * e, http_status status)
     if (pe != NULL) {
         assert(e != pe);
 #if USE_HTCP
-        neighborsHtcpClear(e, NULL, e->mem_obj->request, &e->mem_obj->method, HTCP_CLR_INVALIDATION);
+        neighborsHtcpClear(e, NULL, e->mem_obj->request, e->mem_obj->method, HTCP_CLR_INVALIDATION);
 #endif
         pe->release();
     }
@@ -292,8 +292,7 @@ httpMaybeRemovePublic(StoreEntry * e, http_status status)
     if (pe != NULL) {
         assert(e != pe);
 #if USE_HTCP
-        HttpRequestMethod headMethod(METHOD_HEAD);
-        neighborsHtcpClear(e, NULL, e->mem_obj->request, &headMethod, HTCP_CLR_INVALIDATION);
+        neighborsHtcpClear(e, NULL, e->mem_obj->request, HttpRequestMethod(METHOD_HEAD), HTCP_CLR_INVALIDATION);
 #endif
         pe->release();
     }
index 9c73dec59cc1a5c2d40163037de64ef4ea0929e1..9bb5140adcba64011b40ea8e27533a525a3f8ca2 100644 (file)
@@ -1824,7 +1824,7 @@ neighborsHtcpReply(const cache_key * key, htcpReplyData * htcp, const IPAddress
 }
 
 void
-neighborsHtcpClear(StoreEntry * e, const char *uri, HttpRequest * req, HttpRequestMethod * method, htcp_clr_reason reason)
+neighborsHtcpClear(StoreEntry * e, const char *uri, HttpRequest * req, const HttpRequestMethod &method, htcp_clr_reason reason)
 {
     peer *p;
     char buf[128];
index 3f3f20ae8361e8da11d381adc8d5f06eba926f2a..a0c0eea39a321c18a5facd2d475eec9e870b6775 100644 (file)
@@ -386,7 +386,7 @@ SQUIDCEXTERN void neighborsUdpAck(const cache_key *, icp_common_t *, const IPAdd
 SQUIDCEXTERN void neighborAdd(const char *, const char *, int, int, int, int, int);
 SQUIDCEXTERN void neighbors_init(void);
 #if USE_HTCP
-SQUIDCEXTERN void neighborsHtcpClear(StoreEntry *, const char *, HttpRequest *, HttpRequestMethod *, htcp_clr_reason);
+SQUIDCEXTERN void neighborsHtcpClear(StoreEntry *, const char *, HttpRequest *, const HttpRequestMethod &, htcp_clr_reason);
 #endif
 SQUIDCEXTERN peer *peerFindByName(const char *);
 SQUIDCEXTERN peer *peerFindByNameAndPort(const char *, unsigned short);