[master] 5087989 Teach http_CollectHdr to use arbitrary separators

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Mar 31 14:25:08 CEST 2017


commit 5087989e7bd1afa01d02552fcfe7284609d7d5fd
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Mar 30 14:53:43 2017 +0200

    Teach http_CollectHdr to use arbitrary separators
    
    This done via a new http_CollectHdrSep function, implying a VRT minor
    bump.
    
    Refs #2291

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index cfed8b4..5bc79d7 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -783,6 +783,7 @@ void http_CopyHome(const struct http *hp);
 void http_Unset(struct http *hp, const char *hdr);
 unsigned http_CountHdr(const struct http *hp, const char *hdr);
 void http_CollectHdr(struct http *hp, const char *hdr);
+void http_CollectHdrSep(struct http *hp, const char *hdr, const char *sep);
 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);
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 0c1487d..8ad5ea8 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -1,6 +1,6 @@
 /*-
  * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2015 Varnish Software AS
+ * Copyright (c) 2006-2017 Varnish Software AS
  * All rights reserved.
  *
  * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
@@ -328,12 +328,30 @@ http_CountHdr(const struct http *hp, const char *hdr)
 void
 http_CollectHdr(struct http *hp, const char *hdr)
 {
-	unsigned u, l, ml, f, x, d;
+
+	http_CollectHdrSep(hp, hdr, NULL);
+}
+
+/*--------------------------------------------------------------------
+ * You may prefer to collapse header fields using a different separator.
+ * For Cookie headers, the separator is "; " for example. That's probably
+ * the only example too.
+ */
+
+void
+http_CollectHdrSep(struct http *hp, const char *hdr, const char *sep)
+{
+	unsigned u, l, lsep, ml, f, x, d;
 	char *b = NULL, *e = NULL;
 
 	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
 	if (WS_Overflowed(hp->ws))
 		return;
+
+	if (sep == NULL || *sep == '\0')
+		sep = ",";
+	lsep = strlen(sep);
+
 	l = hdr[0];
 	assert(l == strlen(hdr + 1));
 	assert(hdr[l] == ':');
@@ -371,15 +389,15 @@ http_CollectHdr(struct http *hp, const char *hdr)
 		AN(e);
 
 		/* Append the Nth header we found */
-		if (b < e)
-			*b++ = ',';
 		x = Tlen(hp->hd[u]) - l;
-		if (b + x >= e) {
+		if (b + lsep + x >= e) {
 			http_fail(hp);
 			VSLb(hp->vsl, SLT_LostHeader, "%s", hdr + 1);
 			WS_Release(hp->ws, 0);
 			return;
 		}
+		memcpy(b, sep, lsep);
+		b += lsep;
 		memcpy(b, hp->hd[u].b + *hdr, x);
 		b += x;
 	}
diff --git a/include/vrt.h b/include/vrt.h
index d8e4b4e..ef5204a 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -39,6 +39,8 @@
  * binary/load-time compatible, increment MAJOR version
  *
  *
+ * 6.1 (unreleased):
+ * 	http_CollectHdrSep added
  * 6.0 (2017-03-15):
  *	VRT_hit_for_pass added
  *	VRT_ipcmp added



More information about the varnish-commit mailing list