aboutsummaryrefslogtreecommitdiff
path: root/xs_httpd.h
diff options
context:
space:
mode:
authorshtrophic <christoph@liebender.dev>2025-02-15 14:37:36 +0100
committershtrophic <christoph@liebender.dev>2025-02-15 14:37:36 +0100
commit7611a6bee4bcbad2f1710aafa99aba730e5cf995 (patch)
tree33ab7bee30379e16f6869b2efda5494be8aeb858 /xs_httpd.h
parent3d96c576287736ebdf87e4a7b956842a6c6e055f (diff)
parent3d705b22a67ee913b9bd4473277430bd481cef25 (diff)
Merge tag '2.72' into curl-smtp
Version 2.72 RELEASED.
Diffstat (limited to 'xs_httpd.h')
-rw-r--r--xs_httpd.h54
1 files changed, 34 insertions, 20 deletions
diff --git a/xs_httpd.h b/xs_httpd.h
index cf0d811..4cc8263 100644
--- a/xs_httpd.h
+++ b/xs_httpd.h
@@ -15,41 +15,48 @@ xs_dict *xs_httpd_request(FILE *f, xs_str **payload, int *p_size)
{
xs *q_vars = NULL;
xs *p_vars = NULL;
- xs *l1, *l2;
+ xs *l1;
const char *v;
+ char *saveptr;
xs_socket_timeout(fileno(f), 2.0, 0.0);
/* read the first line and split it */
l1 = xs_strip_i(xs_readline(f));
- l2 = xs_split(l1, " ");
+ char *raw_path;
+ const char *mtd;
+ const char *proto;
- if (xs_list_len(l2) != 3) {
- /* error or timeout */
+ if (!(mtd = strtok_r(l1, " ", &saveptr)) ||
+ !(raw_path = strtok_r(NULL, " ", &saveptr)) ||
+ !(proto = strtok_r(NULL, " ", &saveptr)) ||
+ strtok_r(NULL, " ", &saveptr))
+ return NULL;
+
+ if (!xs_is_string(mtd) || !xs_is_string(raw_path) || !xs_is_string(proto))
return NULL;
- }
xs_dict *req = xs_dict_new();
- req = xs_dict_append(req, "method", xs_list_get(l2, 0));
- req = xs_dict_append(req, "raw_path", xs_list_get(l2, 1));
- req = xs_dict_append(req, "proto", xs_list_get(l2, 2));
+ req = xs_dict_append(req, "method", mtd);
+ req = xs_dict_append(req, "raw_path", raw_path);
+ req = xs_dict_append(req, "proto", proto);
{
- /* split the path with its optional variables */
- const xs_val *udp = xs_list_get(l2, 1);
- xs *pnv = xs_split_n(udp, "?", 1);
-
- /* store the path */
- req = xs_dict_append(req, "path", xs_list_get(pnv, 0));
+ char *q = strchr(raw_path, '?');
/* get the variables */
- q_vars = xs_url_vars(xs_list_get(pnv, 1));
+ if (q) {
+ *q++ = '\0';
+ q_vars = xs_url_vars(q);
+ }
+ /* store the path */
+ req = xs_dict_append(req, "path", raw_path);
}
/* read the headers */
for (;;) {
- xs *l, *p = NULL;
+ xs *l;
l = xs_strip_i(xs_readline(f));
@@ -58,11 +65,18 @@ xs_dict *xs_httpd_request(FILE *f, xs_str **payload, int *p_size)
break;
/* split header and content */
- p = xs_split_n(l, ": ", 1);
+ char *cnt = strchr(l, ':');
+ if (!cnt)
+ continue;
+
+ *cnt++ = '\0';
+ cnt += strspn(cnt, " \r\n\t\v\f");
+ l = xs_rstrip_chars_i(l, " \r\n\t\v\f");
+
+ if (!xs_is_string(cnt))
+ continue;
- if (xs_list_len(p) == 2)
- req = xs_dict_append(req, xs_tolower_i(
- (xs_str *)xs_list_get(p, 0)), xs_list_get(p, 1));
+ req = xs_dict_append(req, xs_tolower_i(l), cnt);
}
xs_socket_timeout(fileno(f), 5.0, 0.0);