aboutsummaryrefslogtreecommitdiff
path: root/xs_httpd.h
diff options
context:
space:
mode:
Diffstat (limited to 'xs_httpd.h')
-rw-r--r--xs_httpd.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/xs_httpd.h b/xs_httpd.h
index 57759c4..0f03599 100644
--- a/xs_httpd.h
+++ b/xs_httpd.h
@@ -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");