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); ...@@ -151,7 +151,7 @@ void b64_settings(const struct http *hp, const char *s);
/* vtc_gzip.c */ /* vtc_gzip.c */
void vtc_gunzip(struct http *, char *, long *); 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 */ /* vtc_subr.c */
struct vsb *vtc_hex_to_bin(struct vtclog *vl, const char *arg); 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) ...@@ -194,26 +194,41 @@ vtc_gunzip(struct http *hp, char *body, long *bodylen)
bprintf(hp->bodylen, "%ld", *bodylen); bprintf(hp->bodylen, "%ld", *bodylen);
} }
void int
vtc_gzip_cmd(struct http *hp, char * const *argv, char **body, long *bodylen) vtc_gzip_cmd(struct http *hp, char * const *av, char **body, long *bodylen)
{ {
char *b; char *b;
AN(hp); AN(hp);
AN(argv); AN(av);
AN(body); AN(body);
AN(bodylen); AN(bodylen);
if (!strcmp(*argv, "-gzipbody")) { if (!strcmp(*av, "-gzipresidual")) {
AZ(*body); hp->gzipresidual = strtoul(av[1], NULL, 0);
vtc_gzip(hp, argv[1], body, bodylen); 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); AN(*body);
} else if (!strcmp(*argv, "-gziplen")) { return (2);
b = synth_body(argv[1], 1); }
if (!strcmp(*av, "-gziplen")) {
if (*body != NULL)
free(*body);
*body = NULL;
b = synth_body(av[1], 1);
vtc_gzip(hp, b, body, bodylen); vtc_gzip(hp, b, body, bodylen);
AN(*body); AN(*body);
free(b); free(b);
} else { return (2);
WRONG("Wrong cmd til vtc_gzip_cmd");
} }
return (0);
} }
...@@ -839,26 +839,13 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, ...@@ -839,26 +839,13 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
body = synth_body(av[1], 0); body = synth_body(av[1], 0);
bodylen = strlen(body); bodylen = strlen(body);
av++; av++;
} else if (!strcmp(*av, "-gzipresidual")) { } else if (!strncmp(*av, "-gzip", 5)) {
hp->gzipresidual = strtoul(av[1], NULL, 0); l = vtc_gzip_cmd(hp, av, &body, &bodylen);
av++; if (l == 0)
} else if (!strcmp(*av, "-gziplevel")) { break;
hp->gziplevel = strtoul(av[1], NULL, 0); av += l;
av++; if (l > 1)
} else if (!strcmp(*av, "-gziplen")) { VSB_printf(hp->vsb, "Content-Encoding: gzip%s", nl);
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 } else
break; break;
} }
......
...@@ -1427,6 +1427,7 @@ static void ...@@ -1427,6 +1427,7 @@ static void
cmd_tx11obj(CMD_ARGS) cmd_tx11obj(CMD_ARGS)
{ {
struct stream *s; struct stream *s;
int i;
int status_done = 1; int status_done = 1;
int method_done = 1; int method_done = 1;
int path_done = 1; int path_done = 1;
...@@ -1597,17 +1598,15 @@ cmd_tx11obj(CMD_ARGS) ...@@ -1597,17 +1598,15 @@ cmd_tx11obj(CMD_ARGS)
f.flags &= ~END_STREAM; f.flags &= ~END_STREAM;
av++; av++;
} }
else if (!strcmp(*av, "-gzipbody")) { else if (!strncmp(*av, "-gzip", 5)) {
vtc_gzip_cmd(s->hp, av, &body, &bodylen); i = vtc_gzip_cmd(s->hp, av, &body, &bodylen);
ENC(hdr, ":content-encoding", "gzip"); if (i == 0)
f.flags &= ~END_STREAM; break;
av++; av += i;
} if (i > 1) {
else if (!strcmp(*av, "-gziplen")) { ENC(hdr, ":content-encoding", "gzip");
vtc_gzip_cmd(s->hp, av, &body, &bodylen); f.flags &= ~END_STREAM;
ENC(hdr, ":content-encoding", "gzip"); }
f.flags &= ~END_STREAM;
av++;
} }
else if (AV_IS("-dep")) { else if (AV_IS("-dep")) {
STRTOU32_CHECK(stid, av, p, vl, "-dep", 0); 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