From: Benno Rice Date: Thu, 18 Sep 2008 02:55:19 +0000 (+1000) Subject: Finish forward-porting HTCP enhancements from squid 2.HEAD. X-Git-Tag: SQUID_3_1_0_1~49^2~9^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8dceeee38d4b1b3a5bfb62bbec9d81fb3b25b224;p=thirdparty%2Fsquid.git Finish forward-porting HTCP enhancements from squid 2.HEAD. - 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. --- diff --git a/src/Server.cc b/src/Server.cc index 830b55217c..deae031843 100644 --- a/src/Server.cc +++ b/src/Server.cc @@ -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); diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index d91ea182d6..b7031641be 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -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; } diff --git a/src/htcp.cc b/src/htcp.cc index b2108c2069..f09f94418f 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -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; } diff --git a/src/htcp.h b/src/htcp.h index ce88858288..c0f02c0f9d 100644 --- a/src/htcp.h +++ b/src/htcp.h @@ -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); diff --git a/src/http.cc b/src/http.cc index 00e1c09102..0db0fd268d 100644 --- a/src/http.cc +++ b/src/http.cc @@ -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(); } diff --git a/src/neighbors.cc b/src/neighbors.cc index 9c73dec59c..9bb5140adc 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -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]; diff --git a/src/protos.h b/src/protos.h index 3f3f20ae83..a0c0eea39a 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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);