]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
- added mime_get_header_field() to support multiple header fields
authorrousskov <>
Thu, 2 Apr 1998 11:45:03 +0000 (11:45 +0000)
committerrousskov <>
Thu, 2 Apr 1998 11:45:03 +0000 (11:45 +0000)
  with the same field-name
- enabled support for only-if-cached directive

src/client.cc
src/client_side.cc
src/enums.h
src/mime.cc
src/protos.h

index dea83d4fafdff8e3c21d4a207ff6ffa359d63218..01135069a0dc5845cf5866359fed5f961ace32a3 100644 (file)
@@ -4,7 +4,7 @@
 
 
 /*
- * $Id: client.cc,v 1.62 1998/03/31 05:37:36 wessels Exp $
+ * $Id: client.cc,v 1.63 1998/04/02 04:45:03 rousskov Exp $
  *
  * DEBUG: section 0     WWW Client
  * AUTHOR: Harvest Derived
@@ -234,7 +234,10 @@ main(int argc, char *argv[])
                break;
            case 'H':
                if (strlen(optarg)) {
+                   char *t;
                    strncpy(extra_hdrs, optarg, sizeof(extra_hdrs));
+                   while ((t = strstr(extra_hdrs, "\\n")))
+                       *t = '\r', *(t+1) = '\n';
                }
                break;
            case 'v':
index 067598bb32a05b82b9fe9ff68c2db448dde2a174..4ecbd0e7ee3bdc11b62feb522054e2708e006c03 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side.cc,v 1.248 1998/04/01 21:23:02 wessels Exp $
+ * $Id: client_side.cc,v 1.249 1998/04/02 04:45:04 rousskov Exp $
  *
  * DEBUG: section 33    Client-side Routines
  * AUTHOR: Duane Wessels
@@ -634,9 +634,8 @@ clientParseRequestHeaders(clientHttpRequest * http)
                request->imslen = atoi(t + 7);
        }
     }
-    if ((t = mime_get_header(request_hdr, "Pragma"))) {
-       if (!strcasecmp(t, "no-cache"))
-           EBIT_SET(request->flags, REQ_NOCACHE);
+    if ((t = mime_get_header_field(request_hdr, "Pragma", "no-cache"))) {
+       EBIT_SET(request->flags, REQ_NOCACHE);
     }
     if (mime_get_header(request_hdr, "Range")) {
        EBIT_SET(request->flags, REQ_NOCACHE);
@@ -674,10 +673,13 @@ clientParseRequestHeaders(clientHttpRequest * http)
     if ((t = mime_get_header(request_hdr, "X-Forwarded-For")))
        fvdbCountForw(t);
 #endif
-    request->max_age = -1;
-    if ((t = mime_get_header(request_hdr, "Cache-control"))) {
-       if (!strncasecmp(t, "Max-age=", 8))
-           request->max_age = atoi(t + 8);
+    if ((t = mime_get_header_field(request_hdr, "Cache-control", "max-age="))) {
+       request->max_age = atoi(t + 8);
+    } else {
+       request->max_age = -1;
+    }
+    if ((t = mime_get_header_field(request_hdr, "Cache-control", "only-if-cached"))) {
+       EBIT_SET(request->flags, REQ_CC_ONLY_IF_CACHED);
     }
     if (request->method == METHOD_TRACE) {
        if ((t = mime_get_header(request_hdr, "Max-Forwards")))
@@ -1362,7 +1364,8 @@ clientProcessRequest(clientHttpRequest * http)
     }
     /* ok, it is a miss or a "dirty" hit (will contact other servers) */
     /* are we allowed to contact other servers? */
-    if (r->cache_control && EBIT_TEST(r->cache_control->mask, CC_ONLY_IF_CACHED)) {
+    if (EBIT_TEST(r->flags, REQ_CC_ONLY_IF_CACHED)) {
+    /* future interface: if (r->cache_control && EBIT_TEST(r->cache_control->mask, CC_ONLY_IF_CACHED)) { */
        /* nope, bailing out */
        clientProcessOnlyIfCachedMiss(http);
        return;
index e7bf5c27a18f12a95e96a36cfb60e38290a9b470..fed737442d57f3522ee6f1055138c7298c08a36b 100644 (file)
@@ -414,7 +414,8 @@ enum {
     REQ_PROXY_KEEPALIVE,
     REQ_PROXYING,
     REQ_REFRESH,
-    REQ_USED_PROXY_AUTH
+    REQ_USED_PROXY_AUTH,
+    REQ_CC_ONLY_IF_CACHED
 };
 
 enum {
index bdd3347c881dc1e51821a0dd8da0cacad0ecf3b6..d91e0e496839acf98ec18521a2ec21da1f5a1b18 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: mime.cc,v 1.58 1998/04/01 00:12:33 wessels Exp $
+ * $Id: mime.cc,v 1.59 1998/04/02 04:45:06 rousskov Exp $
  *
  * DEBUG: section 25    MIME Parsing
  * AUTHOR: Harvest Derived
@@ -123,14 +123,26 @@ static mimeEntry **MimeTableTail = NULL;
 
 static void mimeLoadIconFile(const char *icon);
 
+/* returns a pointer to a field-value of the first matching field-name */
 char *
 mime_get_header(const char *mime, const char *name)
+{
+    return mime_get_header_field(mime, name, NULL);
+}
+
+/*
+ * returns a pointer to a field-value of the first matching field-name where
+ * field-value matches prefix if any
+ */
+char *
+mime_get_header_field(const char *mime, const char *name, const char *prefix)
 {
     LOCAL_ARRAY(char, header, GET_HDR_SZ);
     const char *p = NULL;
     char *q = NULL;
     char got = 0;
-    int namelen = strlen(name);
+    const int namelen = name ? strlen(name) : 0;
+    const int preflen = prefix ? strlen(prefix) : 0;
     int l;
 
     if (!mime || !name)
@@ -158,6 +170,11 @@ mime_get_header(const char *mime, const char *name)
            q++, got = 1;
        while (isspace(*q))
            q++, got = 1;
+       if (got && prefix) {
+           /* we could process list entries here if we had strcasestr(). */
+           /* make sure we did not match a part of another field-value */
+           got = !strncasecmp(q, prefix, preflen) && !isalpha(q[preflen]);
+       }
        if (got) {
            debug(25, 5) ("mime_get_header: returning '%s'\n", q);
            return q;
index 1fdad43ebf15211093a3aab3efd160f59ce11551..1d491e482466acf280c787040f9234400e8f9ea0 100644 (file)
@@ -450,6 +450,7 @@ extern FREE *memBufFreeFunc(MemBuf * mb);
 extern void memBufReport(MemBuf * mb);
 
 extern char *mime_get_header(const char *mime, const char *header);
+char *mime_get_header_field(const char *mime, const char *name, const char *prefix);
 #if OLD_CODE
 extern char *mime_headers_end(const char *mime);
 #endif