[4.1] 65e64b7 Pack the HdrPack iterator into a function so other code than HTTP_GetHdrPack() can also use it.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Sep 8 11:52:24 CEST 2015
commit 65e64b741bd56da8241e65bc419da7f49f9e0ad0
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Sep 7 09:48:39 2015 +0000
Pack the HdrPack iterator into a function so other code than HTTP_GetHdrPack()
can also use it.
Patch by: martin
Some rework by: phk
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 9461429..7c8411a 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -831,8 +831,10 @@ void http_CollectHdr(struct http *hp, const char *hdr);
void http_VSL_log(const struct http *hp);
void HTTP_Merge(struct worker *, struct objcore *, struct http *to);
uint16_t HTTP_GetStatusPack(struct worker *, struct objcore *oc);
-const char *HTTP_GetHdrPack(struct worker *, struct objcore *,
- const char *hdr);
+int HTTP_IterHdrPack(struct worker *, struct objcore *, const char **);
+#define HTTP_FOREACH_PACK(wrk, oc, ptr) \
+ for ((ptr) = NULL; HTTP_IterHdrPack(wrk, oc, &(ptr));)
+const char *HTTP_GetHdrPack(struct worker *, struct objcore *, const char *hdr);
enum sess_close http_DoConnection(struct http *hp);
/* cache_http1_proto.c */
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index fac57cc..9080641 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -806,6 +806,11 @@ http_EstimateWS(const struct http *fm, unsigned how)
/*--------------------------------------------------------------------
* Encode http struct as byte string.
+ *
+ * XXX: We could save considerable special-casing below by encoding also
+ * XXX: H__Status, H__Reason and H__Proto into the string, but it would
+ * XXX: add 26-30 bytes to all encoded objects to save a little code.
+ * XXX: It could possibly be a good idea for later HTTP versions.
*/
void
@@ -895,6 +900,32 @@ HTTP_GetStatusPack(struct worker *wrk, struct objcore *oc)
/*--------------------------------------------------------------------*/
+/* Get the first packed header */
+int
+HTTP_IterHdrPack(struct worker *wrk, struct objcore *oc, const char **p)
+{
+ const char *ptr;
+
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+ AN(p);
+
+ if (*p == NULL) {
+ ptr = ObjGetattr(wrk, oc, OA_HEADERS, NULL);
+ AN(ptr);
+ ptr += 4; /* Skip nhd and status */
+ ptr = strchr(ptr, '\0') + 1; /* Skip :proto: */
+ ptr = strchr(ptr, '\0') + 1; /* Skip :status: */
+ ptr = strchr(ptr, '\0') + 1; /* Skip :reason: */
+ *p = ptr;
+ } else {
+ *p = strchr(*p, '\0') + 1; /* Skip to next header */
+ }
+ if (**p == '\0')
+ return (0);
+ return (1);
+}
+
const char *
HTTP_GetHdrPack(struct worker *wrk, struct objcore *oc, const char *hdr)
{
@@ -911,33 +942,32 @@ HTTP_GetHdrPack(struct worker *wrk, struct objcore *oc, const char *hdr)
assert(hdr[l] == ':');
hdr++;
- ptr = ObjGetattr(wrk, oc, OA_HEADERS, NULL);
- AN(ptr);
+ if (hdr[0] == ':') {
+ /* Special cases */
+ ptr = ObjGetattr(wrk, oc, OA_HEADERS, NULL);
+ AN(ptr);
+ ptr += 4; /* Skip nhd and status */
- /* Skip nhd and status */
- ptr += 4;
- VSL(SLT_Debug, 0, "%d %s", __LINE__, ptr);
-
- /* Skip PROTO, STATUS and REASON */
- if (!strcmp(hdr, ":proto:"))
- return (ptr);
- ptr = strchr(ptr, '\0') + 1;
- if (!strcmp(hdr, ":status:"))
- return (ptr);
- ptr = strchr(ptr, '\0') + 1;
- if (!strcmp(hdr, ":reason:"))
- return (ptr);
- ptr = strchr(ptr, '\0') + 1;
+ if (!strcmp(hdr, ":proto:"))
+ return (ptr);
+ ptr = strchr(ptr, '\0') + 1;
+ if (!strcmp(hdr, ":status:"))
+ return (ptr);
+ ptr = strchr(ptr, '\0') + 1;
+ if (!strcmp(hdr, ":reason:"))
+ return (ptr);
+ WRONG("Unknown magic packed header");
+ }
- while (*ptr != '\0') {
+ HTTP_FOREACH_PACK(wrk, oc, ptr) {
if (!strncasecmp(ptr, hdr, l)) {
ptr += l;
while (vct_islws(*ptr))
ptr++;
return (ptr);
}
- ptr = strchr(ptr, '\0') + 1;
}
+
return (NULL);
}
More information about the varnish-commit
mailing list