summaryrefslogtreecommitdiff
path: root/src/c/urweb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/c/urweb.c')
-rw-r--r--src/c/urweb.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 9e83191e..5f718db6 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -24,7 +24,7 @@ typedef struct {
} cleanup;
struct uw_context {
- char *headers;
+ char *headers, *headers_end;
char *page, *page_front, *page_back;
char *heap, *heap_front, *heap_back;
@@ -46,7 +46,7 @@ extern int uw_inputs_len;
uw_context uw_init(size_t page_len, size_t heap_len) {
uw_context ctx = malloc(sizeof(struct uw_context));
- ctx->headers = NULL;
+ ctx->headers = ctx->headers_end = NULL;
ctx->page_front = ctx->page = malloc(page_len);
ctx->page_back = ctx->page_front + page_len;
@@ -116,11 +116,26 @@ failure_kind uw_begin_init(uw_context ctx) {
return r;
}
-failure_kind uw_begin(uw_context ctx, char *headers, char *path) {
- int r = setjmp(ctx->jmp_buf);
-
+void uw_set_headers(uw_context ctx, char *headers) {
+ char *s = headers, *s2;
ctx->headers = headers;
+ while (s2 = strchr(s, '\r')) {
+ s = s2;
+
+ if (s[1] == 0)
+ break;
+
+ *s = 0;
+ s += 2;
+ }
+
+ ctx->headers_end = s;
+}
+
+failure_kind uw_begin(uw_context ctx, char *path) {
+ int r = setjmp(ctx->jmp_buf);
+
if (r == 0)
uw_handle(ctx, path);
@@ -1065,21 +1080,13 @@ uw_Basis_string uw_Basis_requestHeader(uw_context ctx, uw_Basis_string h) {
while (p = strchr(s, ':')) {
if (p - s == len && !strncasecmp(s, h, len)) {
- s = p + 2;
- if (p = strchr(s, '\r')) {
- uw_Basis_string ret = uw_malloc(ctx, p - s + 1);
- memcpy(ret, s, p - s);
- ret[p - s] = 0;
- return ret;
- }
- else
- return NULL;
+ return p + 2;
} else {
- if (s = strchr(s, '\n'))
- ++s;
+ if ((s = strchr(p, 0)) && s < ctx->headers_end)
+ s += 2;
else
return NULL;
}
}
-
+
}