diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2024-10-04 15:16:52 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2024-10-04 15:16:52 +0200 |
| commit | b8cd00d00fa4dd2c45615c6b0367e3b57e12e98d (patch) | |
| tree | f67e27ac1046c4bd6ba544173c48608679c71d33 | |
| parent | ca70c2ae2217e20cebfe3b8a7aa967cba20e5b4f (diff) | |
http.c: Always call ctx_to_payload
Defining each struct http_payload manually had the risk of missing some
member on the initializer.
This was in fact the case for `n_headers` and `headers`, which were only
assigned by ctx_to_payload, and therefore some specific HTTP requests
would mistakenly not reflect such information to users.
| -rw-r--r-- | http.c | 56 |
1 files changed, 10 insertions, 46 deletions
@@ -1595,24 +1595,14 @@ static int end_boundary(struct http_ctx *const h) /* Found end boundary. */ struct ctx *const c = &h->ctx; struct multiform *const m = &c->u.mf; + struct http_payload p = ctx_to_payload(c); - const struct http_payload p = + p.u.post = (const struct http_post) { - .cookie = - { - .field = c->field, - .value = c->value - }, - - .op = c->op, - .resource = c->resource, - .u.post = - { - .files = m->files, - .pairs = m->pairs, - .nfiles = m->nfiles, - .npairs = m->npairs - } + .files = m->files, + .pairs = m->pairs, + .nfiles = m->nfiles, + .npairs = m->npairs }; return send_payload(h, &p); @@ -2079,23 +2069,10 @@ static int read_body_to_mem(struct http_ctx *const h, const char *const buf, if (p->read >= p->len) { - const struct http_payload pl = - { - .cookie = - { - .field = c->field, - .value = c->value - }, - - .op = c->op, - .resource = c->resource, - .u.post = - { - .data = h->line - } - }; + struct http_payload pl = ctx_to_payload(c); h->line[p->len] = '\0'; + pl.u.post.data = h->line; return send_payload(h, &pl); } @@ -2196,22 +2173,9 @@ static int read_to_file(struct http_ctx *const h, const char *const buf, return -1; else if (p->read >= p->len) { - const struct http_payload pl = - { - .cookie = - { - .field = c->field, - .value = c->value - }, - - .op = c->op, - .resource = c->resource, - .u.put = - { - .tmpname = c->u.put.tmpname - } - }; + struct http_payload pl = ctx_to_payload(c); + pl.u.put.tmpname = c->u.put.tmpname; return send_payload(h, &pl); } |
