[master] c2a512359 Make it possible to get the length from WS_VSB_finish() (ie: H2 headers).

Poul-Henning Kamp phk at FreeBSD.org
Mon Feb 10 09:45:07 UTC 2020


commit c2a5123598061154e89875148dbe96edfb428d83
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Feb 10 09:33:05 2020 +0000

    Make it possible to get the length from WS_VSB_finish() (ie: H2 headers).

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index e83096935..b1f8bdc40 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -796,7 +796,7 @@ int WS_Inside(const struct ws *, const void *, const void *);
 void WS_Assert_Allocated(const struct ws *ws, const void *ptr, ssize_t len);
 
 void WS_VSB_new(struct vsb *, struct ws *);
-char *WS_VSB_finish(struct vsb *, struct ws *);
+char *WS_VSB_finish(struct vsb *, struct ws *, size_t *);
 
 static inline char*
 WS_Front(const struct ws *ws)
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 7a4b07ae5..fe26401eb 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -474,7 +474,7 @@ VRT_StrandsWS(struct ws *ws, const char *h, VCL_STRANDS s)
 		if (s->p[i] != NULL && *s->p[i] != '\0')
 			VSB_cat(vsb, s->p[i]);
 	}
-	return (WS_VSB_finish(vsb, ws));
+	return (WS_VSB_finish(vsb, ws, NULL));
 }
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index aad4db73a..4d2c382db 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -352,7 +352,7 @@ WS_Overflowed(const struct ws *ws)
  *
  *	WS_VSB_new(vsb, ctx->ws);
  *	VSB_printf(vsb, "blablabla");
- *	p = WS_VSB_finish(vsb);
+ *	p = WS_VSB_finish(vsb, NULL);
  *	if (p == NULL)
  *		return (FAILURE);
  */
@@ -375,7 +375,7 @@ WS_VSB_new(struct vsb *vsb, struct ws *ws)
 }
 
 char *
-WS_VSB_finish(struct vsb *vsb, struct ws *ws)
+WS_VSB_finish(struct vsb *vsb, struct ws *ws, size_t *szp)
 {
 	char *p;
 
@@ -384,11 +384,15 @@ WS_VSB_finish(struct vsb *vsb, struct ws *ws)
 		p = VSB_data(vsb);
 		if (p == WS_Front(ws)) {
 			WS_Release(ws, VSB_len(vsb) + 1);
+			if (szp != NULL)
+				*szp = VSB_len(vsb);
 			VSB_delete(vsb);
 			return (p);
 		}
 	}
 	VSB_delete(vsb);
 	WS_Release(ws, 0);
+	if (szp)
+		*szp = 0;
 	return (NULL);
 }


More information about the varnish-commit mailing list