aboutsummaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-11-12 01:28:48 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-11-12 01:29:54 +0100
commit28ba2de389c02a9d47cf6cfd8874e9a3c4770b6c (patch)
tree7cbcbfdf1ca9f78858f8d9ff277f3c079a4f88c3 /http.c
parent747911416eeb7dfa0fbfd226f0c8b37059a8bb1c (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.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/http.c b/http.c
index a475c64..d34f931 100644
--- a/http.c
+++ b/http.c
@@ -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)