Commit 9f48ee00 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Handle the -gzipbody and -gziplen arguments centrally.

parent f6ef5927
......@@ -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);
......
......@@ -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");
}
}
......@@ -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;
......
......@@ -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++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment