summaryrefslogtreecommitdiff
path: root/xs_httpd.h
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-09-23 20:28:23 +0200
committerdefault <nobody@localhost>2022-09-23 20:28:23 +0200
commit1d694a245a56bb4fd90fd917ad3648c2c5449746 (patch)
treecb96eb621ca84ebfdfba40cf859af477639f75d6 /xs_httpd.h
parentbbf5471039a973fed918441150ef76ff0db7682a (diff)
xs_httpd_request() also returns the payload.
Diffstat (limited to 'xs_httpd.h')
-rw-r--r--xs_httpd.h21
1 files changed, 10 insertions, 11 deletions
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();