diff options
author | default <nobody@localhost> | 2022-09-23 20:28:23 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2022-09-23 20:28:23 +0200 |
commit | 1d694a245a56bb4fd90fd917ad3648c2c5449746 (patch) | |
tree | cb96eb621ca84ebfdfba40cf859af477639f75d6 /xs_httpd.h | |
parent | bbf5471039a973fed918441150ef76ff0db7682a (diff) |
xs_httpd_request() also returns the payload.
Diffstat (limited to 'xs_httpd.h')
-rw-r--r-- | xs_httpd.h | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -6,7 +6,7 @@ d_char *xs_url_dec(char *str); d_char *xs_url_vars(char *str); -d_char *xs_httpd_request(FILE *f); +d_char *xs_httpd_request(FILE *f, d_char **payload, int *p_size); void xs_httpd_response(FILE *f, int status, d_char *headers, char *body, int b_size); @@ -69,7 +69,7 @@ d_char *xs_url_vars(char *str) } -d_char *xs_httpd_request(FILE *f) +d_char *xs_httpd_request(FILE *f, d_char **payload, int *p_size) /* processes an httpd connection */ { xs *headers = NULL; @@ -127,19 +127,18 @@ d_char *xs_httpd_request(FILE *f) xs_socket_timeout(fileno(f), 5.0, 0.0); + if ((v = xs_dict_get(headers, "content-length")) != NULL) { + /* if it has a payload, load it */ + *p_size = atoi(v); + *payload = xs_read(f, *p_size); + } + /* does it have a payload with form urlencoded variables? */ v = xs_dict_get(headers, "content-type"); if (v && strcmp(v, "application/x-www-form-urlencoded") == 0) { - if ((v = xs_dict_get(headers, "content-length")) != NULL) { - int cl = atoi(v); - xs *payload; - - if ((payload = xs_read(f, cl)) != NULL) { - xs *upl = xs_url_dec(payload); - p_vars = xs_url_vars(upl); - } - } + xs *upl = xs_url_dec(*payload); + p_vars = xs_url_vars(upl); } else p_vars = xs_dict_new(); |