]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug #1275: Squid internal icons served up with slightly incorrect HTTP
authorhno <>
Thu, 9 Jun 2005 13:07:30 +0000 (13:07 +0000)
committerhno <>
Thu, 9 Jun 2005 13:07:30 +0000 (13:07 +0000)
headers

dynamically reconstruct the Date header on each ENTRY_SPECIAL cache hit,
making it look more like a normal web server.

include/Array.h
src/HttpHeader.cc
src/client_side_reply.cc
src/protos.h

index 9b8e01c229aefebceaf53adddfc23fc4968f0c95..965764daf65b858f918fa1c13df2f2a6a44fe534 100644 (file)
@@ -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<E>::push_back(E obj)
     items[count++] = obj;
 }
 
+template<class E>
+void
+Vector<E>::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<class E>
 E
 Vector<E>::pop_back()
index 4b0202ed448c29c75b7db27c930fcdcb871e3182..a546a622cf2732394afd27e31252fddc43a049d8 100644 (file)
@@ -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)
 {
index 5e0c17d7edc204ae247e481123eb7ddc3fdbcb58..a252235b351f0d918e1b3f08c52901a505b7fc2c 100644 (file)
@@ -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,
index 8d54ca82c4499b7167a664d1026700926b9ee3be..5acc82ee2f8e159fc01e148dab992fbd755296cf 100644 (file)
@@ -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 */