From: rousskov <> Date: Thu, 2 Apr 1998 11:45:03 +0000 (+0000) Subject: - added mime_get_header_field() to support multiple header fields X-Git-Tag: SQUID_3_0_PRE1~3651 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4e41e2771869fce76c7287208e9f298dd7fd56f0;p=thirdparty%2Fsquid.git - added mime_get_header_field() to support multiple header fields with the same field-name - enabled support for only-if-cached directive --- diff --git a/src/client.cc b/src/client.cc index dea83d4faf..01135069a0 100644 --- a/src/client.cc +++ b/src/client.cc @@ -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': diff --git a/src/client_side.cc b/src/client_side.cc index 067598bb32..4ecbd0e7ee 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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; diff --git a/src/enums.h b/src/enums.h index e7bf5c27a1..fed737442d 100644 --- a/src/enums.h +++ b/src/enums.h @@ -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 { diff --git a/src/mime.cc b/src/mime.cc index bdd3347c88..d91e0e4968 100644 --- a/src/mime.cc +++ b/src/mime.cc @@ -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; diff --git a/src/protos.h b/src/protos.h index 1fdad43ebf..1d491e4824 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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