[master] eadcc45 Ignore leading spaces in http_CollectHdr

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


commit eadcc45ee781f54bdd8e41e5cefea001132114da
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Mar 30 16:18:54 2017 +0200

    Ignore leading spaces in http_CollectHdr
    
    The default separator is now ", " to maintain the "pretty collapsing" of
    the headers without risking an extra space with the "; " separator for
    cookies.
    
    Refs #2291
    Refs #2292

diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 8ad5ea8..5d900bf 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -343,13 +343,14 @@ http_CollectHdrSep(struct http *hp, const char *hdr, const char *sep)
 {
 	unsigned u, l, lsep, ml, f, x, d;
 	char *b = NULL, *e = NULL;
+	const char *v;
 
 	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
 	if (WS_Overflowed(hp->ws))
 		return;
 
 	if (sep == NULL || *sep == '\0')
-		sep = ",";
+		sep = ", ";
 	lsep = strlen(sep);
 
 	l = hdr[0];
@@ -390,6 +391,13 @@ http_CollectHdrSep(struct http *hp, const char *hdr, const char *sep)
 
 		/* Append the Nth header we found */
 		x = Tlen(hp->hd[u]) - l;
+
+		v = hp->hd[u].b + *hdr;
+		while (vct_issp(*v)) {
+			v++;
+			x--;
+		}
+
 		if (b + lsep + x >= e) {
 			http_fail(hp);
 			VSLb(hp->vsl, SLT_LostHeader, "%s", hdr + 1);
@@ -398,7 +406,7 @@ http_CollectHdrSep(struct http *hp, const char *hdr, const char *sep)
 		}
 		memcpy(b, sep, lsep);
 		b += lsep;
-		memcpy(b, hp->hd[u].b + *hdr, x);
+		memcpy(b, v, x);
 		b += x;
 	}
 	if (b == NULL)
diff --git a/bin/varnishtest/tests/r02291.vtc b/bin/varnishtest/tests/r02291.vtc
index 25659dd..3a02360 100644
--- a/bin/varnishtest/tests/r02291.vtc
+++ b/bin/varnishtest/tests/r02291.vtc
@@ -13,7 +13,7 @@ logexpect l1 -v v1 {
 	expect * = BereqHeader		"Cookie: user=alice"
 	expect * = BereqHeader		"Cookie: peer=bob"
 	expect * * BereqProtocol	HTTP/2.0
-	expect * = BereqHeader		"cookie: user=alice;  peer=bob"
+	expect * = BereqHeader		"cookie: user=alice; peer=bob"
 } -start
 
 client c1 {
diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc
index ab1741d..d4a4381 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -107,7 +107,7 @@ Description
 Example
 	set beresp.http.served-by = std.fileread("/etc/hostname");
 
-$Function VOID collect(HEADER hdr, STRING sep=",")
+$Function VOID collect(HEADER hdr, STRING sep=", ")
 
 Description
 	Collapses multiple *hdr* headers into one long header.



More information about the varnish-commit mailing list