------------------------------------------------------------ revno: 11210 revision-id: squid3@treenet.co.nz-20110716150759-3legy62d1mfqnys6 parent: squid3@treenet.co.nz-20110716150714-0jxkm28b54mz29y1 committer: Amos Jeffries branch nick: SQUID_3_2 timestamp: Sat 2011-07-16 09:07:59 -0600 message: Port 2.7: act-as-origin for reverse proxy ports Original work by Henrik Nordstrom ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20110716150759-3legy62d1mfqnys6 # target_branch: http://www.squid-cache.org/bzr/squid3/branches\ # /SQUID_3_2 # testament_sha1: 9a6926276d02b0ad403619edbadc87cb1f8ec48c # timestamp: 2011-07-16 15:12:41 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/branches\ # /SQUID_3_2 # base_revision_id: squid3@treenet.co.nz-20110716150714-\ # 0jxkm28b54mz29y1 # # Begin patch === modified file 'doc/release-notes/release-3.2.sgml' --- doc/release-notes/release-3.2.sgml 2011-06-18 08:06:18 +0000 +++ doc/release-notes/release-3.2.sgml 2011-07-16 15:07:59 +0000 @@ -487,6 +487,11 @@

children-idle=N determines how many helper to retain as buffer against sudden traffic loads.

Deprecated children=N in favor of children-max=N. + http_port act-as-origin +

act-as-origin ported from 2.7. + This option corrects several HTTP header issues when operating as a reverse proxy and cache. + Notably the externally visible aging of objects stored in the server-side cache. + icap_send_client_ip

Deprecated in favor of adaptation_send_client_ip which applies to both ICAP and eCAP.

@@ -869,7 +874,6 @@

Not yet ported from 2.7 http_port -

act-as-origin not yet ported from 2.7

urlgroup= not yet ported from 2.6 ignore_ims_on_miss === modified file 'src/ProtoPort.h' --- src/ProtoPort.h 2011-06-18 06:24:59 +0000 +++ src/ProtoPort.h 2011-07-16 15:07:59 +0000 @@ -29,6 +29,7 @@ unsigned int allow_direct:1; /**< Allow direct forwarding in accelerator mode */ unsigned int vhost:1; /**< uses host header */ unsigned int sslBump:1; /**< intercepts CONNECT requests */ + unsigned int actAsOrigin:1; ///< update replies to conform with RFC 2616 unsigned int ignore_cc:1; /**< Ignore request Cache-Control directives */ int vport; /* virtual port support, -1 for dynamic, >0 static*/ === modified file 'src/cache_cf.cc' --- src/cache_cf.cc 2011-07-13 09:04:41 +0000 +++ src/cache_cf.cc 2011-07-16 15:07:59 +0000 @@ -3614,10 +3614,15 @@ s->protocol = xstrdup(token + 9); } else if (strcmp(token, "allow-direct") == 0) { if (!s->accel) { - debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag."); + debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag."); self_destruct(); } s->allow_direct = 1; + } else if (strcmp(token, "act-as-origin") == 0) { + if (!s->accel) { + debugs(3, DBG_IMPORTANT, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag."); + } else + s->actAsOrigin = 1; } else if (strcmp(token, "ignore-cc") == 0) { #if !USE_HTTP_VIOLATIONS if (!s->accel) { === modified file 'src/cf.data.pre' --- src/cf.data.pre 2011-06-18 06:24:59 +0000 +++ src/cf.data.pre 2011-07-16 15:07:59 +0000 @@ -1329,6 +1329,11 @@ protocol= Protocol to reconstruct accelerated requests with. Defaults to http://. + act-as-origin + Act as if this Squid is the origin server. + This currently means generate new Date: and Expires: + headers on HIT instead of adding Age:. + ignore-cc Ignore request Cache-Control headers. Warning: This option violates HTTP specifications if === modified file 'src/client_side_reply.cc' --- src/client_side_reply.cc 2011-06-18 06:24:59 +0000 +++ src/client_side_reply.cc 2011-07-16 15:07:59 +0000 @@ -61,6 +61,7 @@ #include "ipcache.h" #include "log/Tokens.h" #include "MemObject.h" +#include "ProtoPort.h" #include "SquidTime.h" #include "StoreClient.h" #include "Store.h" @@ -1294,6 +1295,25 @@ if (EBIT_TEST(http->storeEntry()->flags, ENTRY_SPECIAL)) { hdr->delById(HDR_DATE); hdr->insertTime(HDR_DATE, squid_curtime); + } else if (http->getConn() && http->getConn()->port->actAsOrigin) { + // Swap the Date: header to current time if we are simulating an origin + HttpHeaderEntry *h = hdr->findEntry(HDR_DATE); + if (h) + hdr->putExt("X-Origin-Date", h->value.termedBuf()); + hdr->delById(HDR_DATE); + hdr->insertTime(HDR_DATE, squid_curtime); + h = hdr->findEntry(HDR_EXPIRES); + if (h && http->storeEntry()->expires >= 0) { + hdr->putExt("X-Origin-Expires", h->value.termedBuf()); + hdr->delById(HDR_EXPIRES); + hdr->insertTime(HDR_EXPIRES, squid_curtime + http->storeEntry()->expires - http->storeEntry()->timestamp); + } + if (http->storeEntry()->timestamp <= squid_curtime) { + // put X-Cache-Age: instead of Age: + char age[64]; + snprintf(age, sizeof(age), "%ld", (long int) squid_curtime - http->storeEntry()->timestamp); + hdr->putExt("X-Cache-Age", age); + } } else if (http->storeEntry()->timestamp <= squid_curtime) { hdr->putInt(HDR_AGE, squid_curtime - http->storeEntry()->timestamp); @@ -1865,6 +1885,7 @@ e = http->storeEntry(); // Copy timestamp from the original entry so the 304 // reply has a meaningful Age: header. + e->timestampsSet(); e->timestamp = timestamp; e->replaceHttpReply(temprep); e->complete();