diff options
| author | grunfink <grunfink@noreply.codeberg.org> | 2025-10-21 13:54:45 +0200 |
|---|---|---|
| committer | grunfink <grunfink@noreply.codeberg.org> | 2025-10-21 13:54:45 +0200 |
| commit | ee875579a649fb51def31949b5ff1ad012fa20c9 (patch) | |
| tree | 9b7c90f92bf89a3474eaacb3bcc0e5ec1fbd4b65 /xs_httpd.h | |
| parent | 0fd993d5c6e3567c41b8ab6147f5490990fc5284 (diff) | |
| parent | bebb2c7439ecdef0266f47dc4b05ab093259e63b (diff) | |
Merge pull request 'Improving Mastodon-api experience and Moshidon support' (#489) from draga79/snac2:master into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/489
Diffstat (limited to 'xs_httpd.h')
| -rw-r--r-- | xs_httpd.h | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -87,6 +87,34 @@ xs_dict *xs_httpd_request(FILE *f, xs_str **payload, int *p_size) *p_size = atoi(v); *payload = xs_read(f, p_size); } + else if ((v = xs_dict_get(req, "transfer-encoding")) != NULL && + xs_startswith(v, "chunked")) { + /* handle chunked transfer encoding */ + xs_str *body = xs_str_new(NULL); + + for (;;) { + xs *line = xs_strip_i(xs_readline(f)); + + /* parse chunk size (in hex) */ + int chunk_size = strtol(line, NULL, 16); + + if (chunk_size <= 0) + break; + + /* read chunk data */ + xs *chunk = xs_read(f, &chunk_size); + if (chunk == NULL) + break; + + body = xs_append_m(body, chunk, chunk_size); + + /* read trailing \r\n after chunk data */ + xs_readline(f); + } + + *p_size = xs_size(body) - 1; /* subtract trailing null */ + *payload = body; + } v = xs_dict_get(req, "content-type"); |