[master] 493288e6a vmod_debug: Add debug.chunked filter

Nils Goroll nils.goroll at uplex.de
Wed Aug 21 17:48:05 UTC 2024


commit 493288e6afa25a41be12d9eb15c4a2d9a5266446
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Aug 21 19:45:06 2024 +0200

    vmod_debug: Add debug.chunked filter
    
    to force chunked encoding delivery for testing

diff --git a/bin/varnishtest/tests/m00048.vtc b/bin/varnishtest/tests/m00048.vtc
index 60440cdf9..6e4263224 100644
--- a/bin/varnishtest/tests/m00048.vtc
+++ b/bin/varnishtest/tests/m00048.vtc
@@ -90,7 +90,7 @@ varnish v1 -vcl {
 	sub vcl_synth {
 		set resp.body = "Ponto Facto, Caesar Transit!";
 		if (req.http.Rot13) {
-			set resp.filters += "rot13 debug.pedantic";
+			set resp.filters += "rot13 debug.chunked debug.pedantic";
 		}
 		return (deliver);
 	}
@@ -99,8 +99,11 @@ varnish v1 -vcl {
 client c1 -repeat 2 {
 	txreq
 	rxresp
+	expect resp.http.Content-Length == 28
 	expect resp.body == "Ponto Facto, Caesar Transit!"
 	txreq -hdr "Rot13: please"
 	rxresp
+	expect resp.http.Content-Length == <undef>
+	expect resp.http.Transfer-Encoding == "chunked"
 	expect resp.body == "Cbagb Snpgb, Pnrfne Genafvg!"
 } -run
diff --git a/vmod/vmod_debug.c b/vmod/vmod_debug.c
index 92e171461..cea472a09 100644
--- a/vmod/vmod_debug.c
+++ b/vmod/vmod_debug.c
@@ -173,6 +173,38 @@ static const struct vdp xyzzy_vdp_rot13 = {
 	.fini  = xyzzy_vdp_rot13_fini,
 };
 
+/**********************************************************************
+ * vdp debug_chunked: force http1 chunked encoding by removing the
+ * Content-Length header
+ *
+ * this happens in a VDP because cnt_transmit() runs after VCL and
+ * restores it
+ */
+
+static int v_matchproto_(vdp_init_f)
+xyzzy_vdp_chunked_init(VRT_CTX, struct vdp_ctx *vdc, void **priv, struct objcore *oc)
+{
+	struct http *hp;
+
+	(void)vdc;
+	(void)oc;
+	(void)priv;
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(vdc->req, REQ_MAGIC);
+	hp = vdc->req->resp;
+	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
+	http_Unset(hp, H_Content_Length);
+
+	return (1);
+}
+
+static const struct vdp xyzzy_vdp_chunked = {
+	.name  = "debug.chunked",
+	.init  = xyzzy_vdp_chunked_init,
+};
+
 /**********************************************************************
  * pedantic tests of the VDP API:
  * - assert that we see a VDP_END
@@ -555,6 +587,7 @@ event_load(VRT_CTX, struct vmod_priv *priv)
 
 	AZ(VRT_AddFilter(ctx, &xyzzy_vfp_rot13, &xyzzy_vdp_rot13));
 	AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_pedantic));
+	AZ(VRT_AddFilter(ctx, NULL, &xyzzy_vdp_chunked));
 	return (0);
 }
 
@@ -718,6 +751,7 @@ event_discard(VRT_CTX, void *priv)
 
 	VRT_RemoveFilter(ctx, &xyzzy_vfp_rot13, &xyzzy_vdp_rot13);
 	VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_pedantic);
+	VRT_RemoveFilter(ctx, NULL, &xyzzy_vdp_chunked);
 
 	if (--loads)
 		return (0);


More information about the varnish-commit mailing list