From: hno <> Date: Thu, 9 Jun 2005 13:07:30 +0000 (+0000) Subject: Bug #1275: Squid internal icons served up with slightly incorrect HTTP X-Git-Tag: SQUID_3_0_PRE4~725 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bbe58ab5f6a2721ce0af440c76d2704fccbb9b6d;p=thirdparty%2Fsquid.git Bug #1275: Squid internal icons served up with slightly incorrect HTTP headers dynamically reconstruct the Date header on each ENTRY_SPECIAL cache hit, making it look more like a normal web server. --- diff --git a/include/Array.h b/include/Array.h index 9b8e01c229..965764daf6 100644 --- a/include/Array.h +++ b/include/Array.h @@ -1,5 +1,5 @@ /* - * $Id: Array.h,v 1.21 2005/04/30 19:32:01 serassio Exp $ + * $Id: Array.h,v 1.22 2005/06/09 07:07:30 hno Exp $ * * AUTHOR: Alex Rousskov * @@ -92,6 +92,8 @@ public: void clean(); void reserve (size_t capacity); void push_back (E); + Vector &operator += (E item) {push_back(item);}; + void insert (E); E &back(); E pop_back(); void preAppend(int app_count); @@ -189,6 +191,21 @@ Vector::push_back(E obj) items[count++] = obj; } +template +void +Vector::insert(E obj) +{ + if (size() >= capacity) + reserve (size() + 1); + + int i; + for (i = count; i > 0; i--) + items[i] = items[i - 1]; + + items[i] = obj; + count += 1; +} + template E Vector::pop_back() diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 4b0202ed44..a546a622cf 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.cc,v 1.105 2005/05/28 20:01:06 serassio Exp $ + * $Id: HttpHeader.cc,v 1.106 2005/06/09 07:07:30 hno Exp $ * * DEBUG: section 55 HTTP Header * AUTHOR: Alex Rousskov @@ -786,6 +786,29 @@ httpHeaderAddEntry(HttpHeader * hdr, HttpHeaderEntry * e) hdr->len += e->name.size() + 2 + e->value.size() + 2; } +/* inserts an entry; + * does not call httpHeaderEntryClone() so one should not reuse "*e" + */ +void +httpHeaderInsertEntry(HttpHeader * hdr, HttpHeaderEntry * e) +{ + assert(hdr && e); + assert_eid(e->id); + + debugs(55, 7, hdr << " adding entry: " << e->id << " at " << + hdr->entries.count); + + if (CBIT_TEST(hdr->mask, e->id)) + Headers[e->id].stat.repCount++; + else + CBIT_SET(hdr->mask, e->id); + + hdr->entries.insert(e); + + /* increment header length, allow for ": " and crlf */ + hdr->len += e->name.size() + 2 + e->value.size() + 2; +} + /* return a list of entries with the same id separated by ',' and ws */ String httpHeaderGetList(const HttpHeader * hdr, http_hdr_type id) @@ -954,6 +977,15 @@ httpHeaderPutTime(HttpHeader * hdr, http_hdr_type id, time_t htime) httpHeaderAddEntry(hdr, httpHeaderEntryCreate(id, NULL, mkrfc1123(htime))); } +void +httpHeaderInsertTime(HttpHeader * hdr, http_hdr_type id, time_t htime) +{ + assert_eid(id); + assert(Headers[id].type == ftDate_1123); /* must be of an appropriate type */ + assert(htime >= 0); + httpHeaderInsertEntry(hdr, httpHeaderEntryCreate(id, NULL, mkrfc1123(htime))); +} + void httpHeaderPutStr(HttpHeader * hdr, http_hdr_type id, const char *str) { diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 5e0c17d7ed..a252235b35 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side_reply.cc,v 1.83 2005/04/18 21:52:42 hno Exp $ + * $Id: client_side_reply.cc,v 1.84 2005/06/09 07:07:30 hno Exp $ * * DEBUG: section 88 Client-side Reply Routines * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c) @@ -1343,7 +1343,11 @@ clientReplyContext::buildReplyHeader() (void) 0; else if (http->storeEntry()->timestamp < 0) (void) 0; - else if (http->storeEntry()->timestamp < squid_curtime) { + + if (EBIT_TEST(http->storeEntry()->flags, ENTRY_SPECIAL)) { + httpHeaderDelById(hdr, HDR_DATE); + httpHeaderInsertTime(hdr, HDR_DATE, squid_curtime); + } else if (http->storeEntry()->timestamp < squid_curtime) { httpHeaderPutInt(hdr, HDR_AGE, squid_curtime - http->storeEntry()->timestamp); /* Signal old objects. NB: rfc 2616 is not clear, diff --git a/src/protos.h b/src/protos.h index 8d54ca82c4..5acc82ee2f 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.505 2005/04/18 21:52:43 hno Exp $ + * $Id: protos.h,v 1.506 2005/06/09 07:07:30 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -393,6 +393,7 @@ SQUIDCEXTERN void httpHeaderPackInto(const HttpHeader * hdr, Packer * p); SQUIDCEXTERN int httpHeaderHas(const HttpHeader * hdr, http_hdr_type type); SQUIDCEXTERN void httpHeaderPutInt(HttpHeader * hdr, http_hdr_type type, int number); SQUIDCEXTERN void httpHeaderPutTime(HttpHeader * hdr, http_hdr_type type, time_t htime); +SQUIDCEXTERN void httpHeaderInsertTime(HttpHeader * hdr, http_hdr_type type, time_t htime); SQUIDCEXTERN void httpHeaderPutStr(HttpHeader * hdr, http_hdr_type type, const char *str); SQUIDCEXTERN void httpHeaderPutAuth(HttpHeader * hdr, const char *auth_scheme, const char *realm); SQUIDCEXTERN void httpHeaderPutCc(HttpHeader * hdr, const HttpHdrCc * cc); @@ -426,6 +427,7 @@ extern int httpHeaderEntryGetInt(const HttpHeaderEntry * e); SQUIDCEXTERN HttpHeaderEntry *httpHeaderGetEntry(const HttpHeader * hdr, HttpHeaderPos * pos); SQUIDCEXTERN HttpHeaderEntry *httpHeaderFindEntry(const HttpHeader * hdr, http_hdr_type id); SQUIDCEXTERN void httpHeaderAddEntry(HttpHeader * hdr, HttpHeaderEntry * e); +SQUIDCEXTERN void httpHeaderInsertEntry(HttpHeader * hdr, HttpHeaderEntry * e); SQUIDCEXTERN HttpHeaderEntry *httpHeaderEntryClone(const HttpHeaderEntry * e); SQUIDCEXTERN void httpHeaderEntryPackInto(const HttpHeaderEntry * e, Packer * p); /* store report about current header usage and other stats */