[4.1] 6385b5e Give the "topline" header-id's a length-field in HTTPHdrPack.

Martin Blix Grydeland martin at varnish-software.com
Mon Sep 7 15:41:16 CEST 2015


commit 6385b5e7d9348998ba008f35bac27938c6072bd4
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Sep 7 09:04:56 2015 +0000

    Give the "topline" header-id's a length-field in HTTPHdrPack.
    
    Patch by:	martin	(slightly polished)

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 648dad4..9461429 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -845,6 +845,9 @@ unsigned HTTP1_Write(const struct worker *w, const struct http *hp, const int*);
 #define HTTPH(a, b, c) extern char b[];
 #include "tbl/http_headers.h"
 #undef HTTPH
+extern const char H__Status[];
+extern const char H__Proto[];
+extern const char H__Reason[];
 
 /* cache_main.c */
 #define VXID(u) ((u) & VSL_IDENTMASK)
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 699bcf5..fd596f7 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -857,7 +857,7 @@ ban_evaluate(struct worker *wrk, const uint8_t *bs, struct objcore *oc,
 			arg1 = HTTP_GetHdrPack(wrk, oc, bt.arg1_spec);
 			break;
 		case BANS_ARG_OBJSTATUS:
-			arg1 = HTTP_GetHdrPack(wrk, oc, ":status");
+			arg1 = HTTP_GetHdrPack(wrk, oc, H__Status);
 			break;
 		default:
 			WRONG("Wrong BAN_ARG code");
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index e832992..fac57cc 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -44,6 +44,10 @@
 #include "tbl/http_headers.h"
 #undef HTTPH
 
+const char H__Status[]	= "\010:status:";
+const char H__Proto[]	= "\007:proto:";
+const char H__Reason[]	= "\010:reason:";
+
 /*--------------------------------------------------------------------
  * These two functions are in an incestous relationship with the
  * order of macros in include/tbl/vsl_tags_http.h
@@ -901,6 +905,12 @@ HTTP_GetHdrPack(struct worker *wrk, struct objcore *oc, const char *hdr)
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	AN(hdr);
 
+	l = hdr[0];
+	assert(l > 0);
+	assert(l == strlen(hdr + 1));
+	assert(hdr[l] == ':');
+	hdr++;
+
 	ptr = ObjGetattr(wrk, oc, OA_HEADERS, NULL);
 	AN(ptr);
 
@@ -909,21 +919,16 @@ HTTP_GetHdrPack(struct worker *wrk, struct objcore *oc, const char *hdr)
 	VSL(SLT_Debug, 0, "%d %s", __LINE__, ptr);
 
 	/* Skip PROTO, STATUS and REASON */
-	if (!strcmp(hdr, ":proto"))
+	if (!strcmp(hdr, ":proto:"))
 		return (ptr);
 	ptr = strchr(ptr, '\0') + 1;
-	if (!strcmp(hdr, ":status"))
+	if (!strcmp(hdr, ":status:"))
 		return (ptr);
 	ptr = strchr(ptr, '\0') + 1;
-	if (!strcmp(hdr, ":reason"))
+	if (!strcmp(hdr, ":reason:"))
 		return (ptr);
 	ptr = strchr(ptr, '\0') + 1;
 
-	l = hdr[0];
-	assert(l == strlen(hdr + 1));
-	assert(hdr[l] == ':');
-	hdr++;
-
 	while (*ptr != '\0') {
 		if (!strncasecmp(ptr, hdr, l)) {
 			ptr += l;
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index cc302c5..c51007b 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -157,7 +157,7 @@ VRT_r_obj_proto(VRT_CTX)
 	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
 	CHECK_OBJ_NOTNULL(ctx->req->objcore, OBJCORE_MAGIC);
 
-	return (HTTP_GetHdrPack(ctx->req->wrk, ctx->req->objcore, ":proto"));
+	return (HTTP_GetHdrPack(ctx->req->wrk, ctx->req->objcore, H__Proto));
 }
 
 const char *
@@ -167,7 +167,7 @@ VRT_r_obj_reason(VRT_CTX)
 	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
 	CHECK_OBJ_NOTNULL(ctx->req->objcore, OBJCORE_MAGIC);
 
-	return (HTTP_GetHdrPack(ctx->req->wrk, ctx->req->objcore, ":reason"));
+	return (HTTP_GetHdrPack(ctx->req->wrk, ctx->req->objcore, H__Reason));
 }
 
 /*--------------------------------------------------------------------



More information about the varnish-commit mailing list