diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-12-10 15:20:36 -0500 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-12-10 15:20:36 -0500 |
commit | 5902e311a458e8a6983bf3fbf7d34c78a3ad229d (patch) | |
tree | a96bb576eb23eb6f7f8b66cd897787235e0980e1 /src | |
parent | b04e123d0e1159d431aae00c3e8f1cc4a1b95684 (diff) |
Basis.currentUrl, plus redirect debugging
Diffstat (limited to 'src')
-rw-r--r-- | src/c/request.c | 2 | ||||
-rw-r--r-- | src/c/urweb.c | 34 |
2 files changed, 34 insertions, 2 deletions
diff --git a/src/c/request.c b/src/c/request.c index 2357a86b..a314bb19 100644 --- a/src/c/request.c +++ b/src/c/request.c @@ -169,6 +169,8 @@ request_result uw_request(uw_request_context rc, uw_context ctx, size_t boundary_len; char *inputs; + uw_set_currentUrl(ctx, path); + if (!strcmp(method, "POST")) { char *clen_s = uw_Basis_requestHeader(ctx, "Content-length"); if (!clen_s) { diff --git a/src/c/urweb.c b/src/c/urweb.c index 476e3794..154e085a 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -384,6 +384,8 @@ struct uw_context { global *globals; size_t n_globals; + char *current_url; + char error_message[ERROR_BUF_LEN]; }; @@ -437,6 +439,8 @@ uw_context uw_init() { ctx->globals = malloc(0); ctx->n_globals = 0; + ctx->current_url = ""; + return ctx; } @@ -3048,7 +3052,7 @@ __attribute__((noreturn)) void uw_return_blob(uw_context ctx, uw_Basis_blob b, u buf_check(&ctx->outHeaders, INTS_MAX); sprintf(ctx->outHeaders.front, "%d%n", b.size, &len); ctx->outHeaders.front += len; - uw_write_header(ctx, "\r\n"); + uw_write_header(ctx, "\r\n"); buf_append(&ctx->page, b.data, b.size); @@ -3063,12 +3067,30 @@ __attribute__((noreturn)) void uw_return_blob(uw_context ctx, uw_Basis_blob b, u __attribute__((noreturn)) void uw_redirect(uw_context ctx, uw_Basis_string url) { cleanup *cl; int len; + char *s; ctx->returning_indirectly = 1; - buf_reset(&ctx->outHeaders); buf_reset(&ctx->page); + buf_check(&ctx->page, buf_used(&ctx->outHeaders)+1); + memcpy(ctx->page.start, ctx->outHeaders.start, buf_used(&ctx->outHeaders)); + ctx->page.start[buf_used(&ctx->outHeaders)] = 0; + buf_reset(&ctx->outHeaders); uw_write_header(ctx, on_redirect); + + s = strchr(ctx->page.start, '\n'); + if (s) { + char *s2; + for (++s; s2 = strchr(s, '\n'); s = s2+1) { + *s2 = 0; + printf("Line: %s\n", s); + if (!strncmp(s, "Set-Cookie: ", 12)) { + uw_write_header(ctx, s); + uw_write_header(ctx, "\n"); + } + } + } + uw_write_header(ctx, "Location: "); uw_write_header(ctx, url); uw_write_header(ctx, "\r\n\r\n"); @@ -3228,3 +3250,11 @@ uw_Basis_char uw_Basis_tolower(uw_context ctx, uw_Basis_char c) { uw_Basis_char uw_Basis_toupper(uw_context ctx, uw_Basis_char c) { return toupper(c); } + +uw_Basis_string uw_Basis_currentUrl(uw_context ctx) { + return ctx->current_url; +} + +void uw_set_currentUrl(uw_context ctx, char *s) { + ctx->current_url = s; +} |