[master] 7fa722836 Collect all the body-gzip stuff one place.

Poul-Henning Kamp phk at FreeBSD.org
Tue May 9 07:53:08 UTC 2023


commit 7fa722836fd55d09a6fbe29bb30b475acdc01f78
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue May 9 06:51:47 2023 +0000

    Collect all the body-gzip stuff one place.

diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index 92d9acf12..e7513092e 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -151,7 +151,7 @@ void b64_settings(const struct http *hp, const char *s);
 
 /* vtc_gzip.c */
 void vtc_gunzip(struct http *, char *, long *);
-void vtc_gzip_cmd(struct http *hp, char * const *argv, char **body, long *bodylen);
+int vtc_gzip_cmd(struct http *hp, char * const *argv, char **body, long *bodylen);
 
 /* vtc_subr.c */
 struct vsb *vtc_hex_to_bin(struct vtclog *vl, const char *arg);
diff --git a/bin/varnishtest/vtc_gzip.c b/bin/varnishtest/vtc_gzip.c
index a3c4b3c0f..f38699b33 100644
--- a/bin/varnishtest/vtc_gzip.c
+++ b/bin/varnishtest/vtc_gzip.c
@@ -194,26 +194,41 @@ vtc_gunzip(struct http *hp, char *body, long *bodylen)
 	bprintf(hp->bodylen, "%ld", *bodylen);
 }
 
-void
-vtc_gzip_cmd(struct http *hp, char * const *argv, char **body, long *bodylen)
+int
+vtc_gzip_cmd(struct http *hp, char * const *av, char **body, long *bodylen)
 {
 	char *b;
 
 	AN(hp);
-	AN(argv);
+	AN(av);
 	AN(body);
 	AN(bodylen);
 
-	if (!strcmp(*argv, "-gzipbody")) {
-		AZ(*body);
-		vtc_gzip(hp, argv[1], body, bodylen);
+	if (!strcmp(*av, "-gzipresidual")) {
+		hp->gzipresidual = strtoul(av[1], NULL, 0);
+		return (1);
+	}
+	if (!strcmp(*av, "-gziplevel")) {
+		hp->gziplevel = strtoul(av[1], NULL, 0);
+		return (1);
+	}
+	if (!strcmp(*av, "-gzipbody")) {
+		if (*body != NULL)
+			free(*body);
+		*body = NULL;
+		vtc_gzip(hp, av[1], body, bodylen);
 		AN(*body);
-	} else if (!strcmp(*argv, "-gziplen")) {
-		b = synth_body(argv[1], 1);
+		return (2);
+	}
+	if (!strcmp(*av, "-gziplen")) {
+		if (*body != NULL)
+			free(*body);
+		*body = NULL;
+		b = synth_body(av[1], 1);
 		vtc_gzip(hp, b, body, bodylen);
 		AN(*body);
 		free(b);
-	} else {
-		WRONG("Wrong cmd til vtc_gzip_cmd");
+		return (2);
 	}
+	return (0);
 }
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index aab1626da..68b9d5936 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -839,26 +839,13 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
 			body = synth_body(av[1], 0);
 			bodylen = strlen(body);
 			av++;
-		} else if (!strcmp(*av, "-gzipresidual")) {
-			hp->gzipresidual = strtoul(av[1], NULL, 0);
-			av++;
-		} else if (!strcmp(*av, "-gziplevel")) {
-			hp->gziplevel = strtoul(av[1], NULL, 0);
-			av++;
-		} else if (!strcmp(*av, "-gziplen")) {
-			assert(body == nullbody);
-			free(body);
-			body = NULL;
-			vtc_gzip_cmd(hp, av, &body, &bodylen);
-			VSB_printf(hp->vsb, "Content-Encoding: gzip%s", nl);
-			av++;
-		} else if (!strcmp(*av, "-gzipbody")) {
-			assert(body == nullbody);
-			free(body);
-			body = NULL;
-			vtc_gzip_cmd(hp, av, &body, &bodylen);
-			VSB_printf(hp->vsb, "Content-Encoding: gzip%s", nl);
-			av++;
+		} else if (!strncmp(*av, "-gzip", 5)) {
+			l = vtc_gzip_cmd(hp, av, &body, &bodylen);
+			if (l == 0)
+				break;
+			av += l;
+			if (l > 1)
+				VSB_printf(hp->vsb, "Content-Encoding: gzip%s", nl);
 		} else
 			break;
 	}
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index 68c36b4f9..72a4399fc 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -1427,6 +1427,7 @@ static void
 cmd_tx11obj(CMD_ARGS)
 {
 	struct stream *s;
+	int i;
 	int status_done = 1;
 	int method_done = 1;
 	int path_done = 1;
@@ -1597,17 +1598,15 @@ cmd_tx11obj(CMD_ARGS)
 				f.flags &= ~END_STREAM;
 				av++;
 			}
-			else if (!strcmp(*av, "-gzipbody")) {
-				vtc_gzip_cmd(s->hp, av, &body, &bodylen);
-				ENC(hdr, ":content-encoding", "gzip");
-				f.flags &= ~END_STREAM;
-				av++;
-			}
-			else if (!strcmp(*av, "-gziplen")) {
-				vtc_gzip_cmd(s->hp, av, &body, &bodylen);
-				ENC(hdr, ":content-encoding", "gzip");
-				f.flags &= ~END_STREAM;
-				av++;
+			else if (!strncmp(*av, "-gzip", 5)) {
+				i = vtc_gzip_cmd(s->hp, av, &body, &bodylen);
+				if (i == 0)
+					break;
+				av += i;
+				if (i > 1) {
+					ENC(hdr, ":content-encoding", "gzip");
+					f.flags &= ~END_STREAM;
+				}
 			}
 			else if (AV_IS("-dep")) {
 				STRTOU32_CHECK(stid, av, p, vl, "-dep", 0);


More information about the varnish-commit mailing list