From 1d694a245a56bb4fd90fd917ad3648c2c5449746 Mon Sep 17 00:00:00 2001 From: default Date: Fri, 23 Sep 2022 20:28:23 +0200 Subject: xs_httpd_request() also returns the payload. --- xs_httpd.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'xs_httpd.h') diff --git a/xs_httpd.h b/xs_httpd.h index d15a473..d56226f 100644 --- a/xs_httpd.h +++ b/xs_httpd.h @@ -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(); -- cgit v1.2.3