[master] 9f48ee000 Handle the -gzipbody and -gziplen arguments centrally.
Poul-Henning Kamp
phk at FreeBSD.org
Tue May 9 05:49:08 UTC 2023
commit 9f48ee000efcf816aa29f3c03bc7b87ded5002f5
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue May 9 05:47:15 2023 +0000
Handle the -gzipbody and -gziplen arguments centrally.
diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index ab0b8031a..92d9acf12 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -150,8 +150,8 @@ void stop_h2(struct http *hp);
void b64_settings(const struct http *hp, const char *s);
/* vtc_gzip.c */
-void vtc_gzip(struct http *, const char *, char **, long *);
void vtc_gunzip(struct http *, char *, long *);
+void 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 02700bf69..a3c4b3c0f 100644
--- a/bin/varnishtest/vtc_gzip.c
+++ b/bin/varnishtest/vtc_gzip.c
@@ -103,7 +103,7 @@ vtc_gzip_vsb(struct vtclog *vl, int fatal, int gzip_level, const struct vsb *vin
return (vout);
}
-void
+static void
vtc_gzip(struct http *hp, const char *input, char **body, long *bodylen)
{
struct vsb *vin, *vout;
@@ -193,3 +193,27 @@ vtc_gunzip(struct http *hp, char *body, long *bodylen)
vtc_dump(hp->vl, 4, "body", body, *bodylen);
bprintf(hp->bodylen, "%ld", *bodylen);
}
+
+void
+vtc_gzip_cmd(struct http *hp, char * const *argv, char **body, long *bodylen)
+{
+ char *b;
+
+ AN(hp);
+ AN(argv);
+ AN(body);
+ AN(bodylen);
+
+ if (!strcmp(*argv, "-gzipbody")) {
+ AZ(*body);
+ vtc_gzip(hp, argv[1], body, bodylen);
+ AN(*body);
+ } else if (!strcmp(*argv, "-gziplen")) {
+ b = synth_body(argv[1], 1);
+ vtc_gzip(hp, b, body, bodylen);
+ AN(*body);
+ free(b);
+ } else {
+ WRONG("Wrong cmd til vtc_gzip_cmd");
+ }
+}
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 4c646d337..aab1626da 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -848,18 +848,16 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
} else if (!strcmp(*av, "-gziplen")) {
assert(body == nullbody);
free(body);
- b = synth_body(av[1], 1);
- vtc_gzip(hp, b, &body, &bodylen);
- free(b);
+ body = NULL;
+ vtc_gzip_cmd(hp, av, &body, &bodylen);
VSB_printf(hp->vsb, "Content-Encoding: gzip%s", nl);
- // vtc_hexdump(hp->vl, 4, "gzip", (void*)body, bodylen);
av++;
} else if (!strcmp(*av, "-gzipbody")) {
assert(body == nullbody);
free(body);
- vtc_gzip(hp, av[1], &body, &bodylen);
+ body = NULL;
+ vtc_gzip_cmd(hp, av, &body, &bodylen);
VSB_printf(hp->vsb, "Content-Encoding: gzip%s", nl);
- // vtc_hexdump(hp->vl, 4, "gzip", (void*)body, bodylen);
av++;
} else
break;
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index 42410e45f..68c36b4f9 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -1443,7 +1443,7 @@ cmd_tx11obj(CMD_ARGS)
/*XXX: do we need a better api? yes we do */
struct hpk_hdr hdr;
char *cmd_str = *av;
- char *b, *p;
+ char *p;
CAST_OBJ_NOTNULL(s, priv, STREAM_MAGIC);
INIT_FRAME(f, CONTINUATION, 0, s->id, END_HEADERS);
@@ -1598,19 +1598,13 @@ cmd_tx11obj(CMD_ARGS)
av++;
}
else if (!strcmp(*av, "-gzipbody")) {
- AZ(body);
- vtc_gzip(s->hp, av[1], &body, &bodylen);
- AN(body);
+ vtc_gzip_cmd(s->hp, av, &body, &bodylen);
ENC(hdr, ":content-encoding", "gzip");
f.flags &= ~END_STREAM;
av++;
}
else if (!strcmp(*av, "-gziplen")) {
- AZ(body);
- b = synth_body(av[1], 1);
- vtc_gzip(s->hp, b, &body, &bodylen);
- AN(body);
- free(b);
+ vtc_gzip_cmd(s->hp, av, &body, &bodylen);
ENC(hdr, ":content-encoding", "gzip");
f.flags &= ~END_STREAM;
av++;
More information about the varnish-commit
mailing list