Commit 7fa72283 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Collect all the body-gzip stuff one place.

parent 9f48ee00
......@@ -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);
......
......@@ -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);
}
......@@ -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;
}
......
......@@ -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);
......
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