summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/urweb.h3
-rw-r--r--src/c/driver.c4
-rw-r--r--src/c/urweb.c41
3 files changed, 29 insertions, 19 deletions
diff --git a/include/urweb.h b/include/urweb.h
index c7d15a1c..301129c5 100644
--- a/include/urweb.h
+++ b/include/urweb.h
@@ -15,7 +15,8 @@ void uw_reset_keep_request(uw_context);
void uw_reset_keep_error_message(uw_context);
failure_kind uw_begin_init(uw_context);
-failure_kind uw_begin(uw_context, char *headers, char *path);
+void uw_set_headers(uw_context, char *headers);
+failure_kind uw_begin(uw_context, char *path);
__attribute__((noreturn)) void uw_error(uw_context, failure_kind, const char *fmt, ...);
char *uw_error_message(uw_context);
diff --git a/src/c/driver.c b/src/c/driver.c
index 4c54d3ba..ac968dc9 100644
--- a/src/c/driver.c
+++ b/src/c/driver.c
@@ -188,6 +188,8 @@ static void *worker(void *data) {
printf("Serving URI %s....\n", path);
+ uw_set_headers(ctx, headers);
+
while (1) {
if (uw_db_begin(ctx)) {
printf("Error running SQL BEGIN\n");
@@ -209,7 +211,7 @@ static void *worker(void *data) {
uw_write(ctx, "<html>");
strcpy(path_copy, path);
- fk = uw_begin(ctx, headers, path_copy);
+ fk = uw_begin(ctx, path_copy);
if (fk == SUCCESS) {
uw_write(ctx, "</html>");
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;
}
}
-
+
}