diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-11-12 01:28:48 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-11-12 01:29:54 +0100 |
| commit | 28ba2de389c02a9d47cf6cfd8874e9a3c4770b6c (patch) | |
| tree | 7cbcbfdf1ca9f78858f8d9ff277f3c079a4f88c3 /http.c | |
| parent | 747911416eeb7dfa0fbfd226f0c8b37059a8bb1c (diff) | |
http.c: Avoid writing body for HEAD requests
As opposed to GET or POST requests, HEAD must not write any body bytes.
Diffstat (limited to 'http.c')
| -rw-r--r-- | http.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -98,6 +98,7 @@ struct http_ctx struct http_response r; off_t n; struct dynstr d; + enum http_op op; } wctx; /* From RFC9112, section 3 (Request line): @@ -582,6 +583,11 @@ static int write_ctx_free(struct write_ctx *const w) return ret; } +static bool must_write_body(const struct write_ctx *const w) +{ + return w->op != HTTP_OP_HEAD; +} + static int write_header_cr_line(struct http_ctx *const h, bool *const close) { struct write_ctx *const w = &h->wctx; @@ -597,7 +603,7 @@ static int write_header_cr_line(struct http_ctx *const h, bool *const close) dynstr_free(d); - if (w->r.n) + if (w->r.n && must_write_body(w)) { w->state = BODY_LINE; w->n = 0; @@ -914,6 +920,7 @@ static int process_payload(struct http_ctx *const h, const char *const line) const struct http_payload p = ctx_to_payload(c); const int ret = h->cfg.payload(&p, &h->wctx.r, h->cfg.user); + h->wctx.op = c->op; ctx_free(c); if (ret) |
