static void cmd_http_rxresp(CMD_ARGS) { struct http *hp; int has_obj = 1; (void)cmd; (void)vl; CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); ONLY_CLIENT(hp, av); assert(!strcmp(av[0], "rxresp")); av++; for(; *av != NULL; av++) if (!strcmp(*av, "-no_obj")) has_obj = 0; else vtc_log(hp->vl, 0, "Unknown http rxresp spec: %s\n", *av); http_rxhdr(hp); http_splitheader(hp, 0); hp->body = hp->rxbuf + hp->prxbuf; if (!has_obj) return; else if (!strcmp(hp->resp[1], "200")) http_swallow_body(hp, hp->resp, 1); else http_swallow_body(hp, hp->resp, 0); vtc_log(hp->vl, 4, "bodylen = %s", hp->bodylen); }
static void cmd_http_gunzip_body(CMD_ARGS) { int i; z_stream vz; struct http *hp; char *p; unsigned l; (void)cmd; (void)vl; CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); ONLY_CLIENT(hp, av); memset(&vz, 0, sizeof vz); if (hp->body[0] != (char)0x1f || hp->body[1] != (char)0x8b) vtc_log(hp->vl, hp->fatal, "Gunzip error: Body lacks gzip magics"); vz.next_in = TRUST_ME(hp->body); vz.avail_in = hp->bodyl; l = hp->bodyl * 10; p = calloc(l, 1); AN(p); vz.next_out = TRUST_ME(p); vz.avail_out = l; assert(Z_OK == inflateInit2(&vz, 31)); i = inflate(&vz, Z_FINISH); hp->bodyl = vz.total_out; memcpy(hp->body, p, hp->bodyl); free(p); vtc_log(hp->vl, 3, "new bodylen %u", hp->bodyl); vtc_dump(hp->vl, 4, "body", hp->body, hp->bodyl); bprintf(hp->bodylen, "%u", hp->bodyl); vtc_log(hp->vl, 4, "startbit = %ju %ju/%ju", (uintmax_t)vz.start_bit, (uintmax_t)vz.start_bit >> 3, (uintmax_t)vz.start_bit & 7); vtc_log(hp->vl, 4, "lastbit = %ju %ju/%ju", (uintmax_t)vz.last_bit, (uintmax_t)vz.last_bit >> 3, (uintmax_t)vz.last_bit & 7); vtc_log(hp->vl, 4, "stopbit = %ju %ju/%ju", (uintmax_t)vz.stop_bit, (uintmax_t)vz.stop_bit >> 3, (uintmax_t)vz.stop_bit & 7); if (i != Z_STREAM_END) vtc_log(hp->vl, hp->fatal, "Gunzip error = %d (%s) in:%jd out:%jd", i, vz.msg, (intmax_t)vz.total_in, (intmax_t)vz.total_out); assert(Z_OK == inflateEnd(&vz)); }
static void cmd_http_rxrespbody(CMD_ARGS) { struct http *hp; (void)cmd; (void)vl; CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); ONLY_CLIENT(hp, av); AZ(strcmp(av[0], "rxrespbody")); av++; for(; *av != NULL; av++) vtc_log(hp->vl, 0, "Unknown http rxreq spec: %s\n", *av); http_swallow_body(hp, hp->resp, 0); vtc_log(hp->vl, 4, "bodylen = %s", hp->bodylen); }
static void cmd_http_rxchunk(CMD_ARGS) { struct http *hp; int ll, i; (void)cmd; (void)vl; CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); ONLY_CLIENT(hp, av); i = http_rxchunk(hp); if (i == 0) { ll = hp->rxbuf + hp->prxbuf - hp->body; hp->bodyl = ll; sprintf(hp->bodylen, "%d", ll); vtc_log(hp->vl, 4, "bodylen = %s", hp->bodylen); } }
/* SECTION: client-server.spec.rxreqhdrs * * rxresp (client only) * Receive and parse a response's headers. */ static void cmd_http_rxresphdrs(CMD_ARGS) { struct http *hp; (void)cmd; (void)vl; CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); ONLY_CLIENT(hp, av); AZ(strcmp(av[0], "rxresphdrs")); av++; for(; *av != NULL; av++) vtc_log(hp->vl, 0, "Unknown http rxreq spec: %s\n", *av); http_rxhdr(hp); http_splitheader(hp, 0); if (http_count_header(hp->resp, "Content-Length") > 1) vtc_log(hp->vl, 0, "Multiple Content-Length headers.\n"); }
static void cmd_http_txreq(CMD_ARGS) { struct http *hp; const char *req = "GET"; const char *url = "/"; const char *proto = "HTTP/1.1"; (void)cmd; (void)vl; CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); ONLY_CLIENT(hp, av); AZ(strcmp(av[0], "txreq")); av++; VSB_clear(hp->vsb); for(; *av != NULL; av++) { if (!strcmp(*av, "-url")) { url = av[1]; av++; } else if (!strcmp(*av, "-proto")) { proto = av[1]; av++; } else if (!strcmp(*av, "-req")) { req = av[1]; av++; } else break; } VSB_printf(hp->vsb, "%s %s %s%s", req, url, proto, nl); av = http_tx_parse_args(av, vl, hp, NULL); if (*av != NULL) vtc_log(hp->vl, 0, "Unknown http txreq spec: %s\n", *av); http_write(hp, 4, "txreq"); }
static void cmd_http_txreq(CMD_ARGS) { struct http *hp; const char *req = "GET"; const char *url = "/"; const char *proto = "HTTP/1.1"; const char *body = NULL; (void)cmd; (void)vl; CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); ONLY_CLIENT(hp, av); assert(!strcmp(av[0], "txreq")); av++; VSB_clear(hp->vsb); for(; *av != NULL; av++) { if (!strcmp(*av, "-url")) { url = av[1]; av++; } else if (!strcmp(*av, "-proto")) { proto = av[1]; av++; } else if (!strcmp(*av, "-req")) { req = av[1]; av++; } else break; } VSB_printf(hp->vsb, "%s %s %s%s", req, url, proto, nl); for(; *av != NULL; av++) { if (!strcmp(*av, "-hdr")) { VSB_printf(hp->vsb, "%s%s", av[1], nl); av++; } else break; } for(; *av != NULL; av++) { if (!strcmp(*av, "-body")) { AZ(body); body = av[1]; av++; } else if (!strcmp(*av, "-bodylen")) { AZ(body); body = synth_body(av[1], 0); av++; } else break; } if (*av != NULL) vtc_log(hp->vl, 0, "Unknown http txreq spec: %s\n", *av); if (body != NULL) VSB_printf(hp->vsb, "Content-Length: %ju%s", (uintmax_t)strlen(body), nl); VSB_cat(hp->vsb, nl); if (body != NULL) { VSB_cat(hp->vsb, body); VSB_cat(hp->vsb, nl); } http_write(hp, 4, "txreq"); }