[master] 1dbc68841 Change VRT_SetHdr() to take a `const char*` and VCL_STRANDS, either or both of which are allowed to be NULL.

Poul-Henning Kamp phk at FreeBSD.org
Thu Aug 19 12:50:07 UTC 2021


commit 1dbc688417c28789a8e1674e3dfce67e7ce6deab
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Aug 19 12:44:13 2021 +0000

    Change VRT_SetHdr() to take a `const char*` and VCL_STRANDS,
    either or both of which are allowed to be NULL.
    
    (Part of STRING_LIST eradication)

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 17e406edf..2cf320ac7 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -704,28 +704,55 @@ VRT_UnsetHdr(VRT_CTX , VCL_HEADER hs)
 }
 
 VCL_VOID
-VRT_SetHdr(VRT_CTX , VCL_HEADER hs, const char *p, ...)
+VRT_SetHdr(VRT_CTX , VCL_HEADER hs, const char *pfx, VCL_STRANDS s)
 {
 	VCL_HTTP hp;
-	va_list ap;
-	const char *b;
+	unsigned u, l;
+	char *p, *b;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	AN(hs);
 	AN(hs->what);
 	hp = VRT_selecthttp(ctx, hs->where);
 	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
-	va_start(ap, p);
-	b = VRT_String(hp->ws, hs->what + 1, p, ap);
-	va_end(ap);
-	if (b == NULL) {
+
+	u = WS_ReserveAll(hp->ws);
+	l = hs->what[0] + 1;
+	if (pfx != NULL)
+		l += strlen(pfx);
+	if (u <= l) {
+		WS_Release(hp->ws, 0);
+		WS_MarkOverflow(hp->ws);
 		VSLb(ctx->vsl, SLT_LostHeader, "%s", hs->what + 1);
 		return;
 	}
-	if (FEATURE(FEATURE_VALIDATE_HEADERS) && ! validhdr(b)) {
+	b = WS_Reservation(hp->ws);
+	if (s != NULL) {
+		p = VRT_Strands(b + l, u - l, s);
+		if (p == NULL) {
+			WS_Release(hp->ws, 0);
+			WS_MarkOverflow(hp->ws);
+			VSLb(ctx->vsl, SLT_LostHeader, "%s", hs->what + 1);
+			return;
+		}
+	} else {
+		b[l] = '\0';
+	}
+	p = b;
+	memcpy(p, hs->what + 1, hs->what[0]);
+	p += hs->what[0];
+	*p++ = ' ';
+	if (pfx != NULL) {
+		l = strlen(pfx);
+		memcpy(p, pfx, l);
+		p += l;
+	}
+	if (FEATURE(FEATURE_VALIDATE_HEADERS) && !validhdr(b)) {
+		WS_Release(hp->ws, 0);
 		VRT_fail(ctx, "Bad header %s", b);
 		return;
 	}
+	WS_ReleaseP(hp->ws, strchr(p, '\0') + 1);
 	http_Unset(hp, hs->what);
 	http_SetHeader(hp, b);
 }


More information about the varnish-commit mailing list