From 44db3e6164b414f4724c9971fe550036ebb706c3 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sat, 8 Nov 2008 10:46:14 -0500 Subject: [getCookie] reads cookie settings from current page generation --- src/c/urweb.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/c/urweb.c') diff --git a/src/c/urweb.c b/src/c/urweb.c index e50d6965..e8c75275 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -341,6 +341,7 @@ void uw_write_header(uw_context ctx, uw_Basis_string s) { uw_check_headers(ctx, len + 1); strcpy(ctx->outHeaders_front, s); ctx->outHeaders_front += len; + *ctx->outHeaders_front = 0; } static void uw_check(uw_context ctx, size_t extra) { @@ -1172,7 +1173,24 @@ uw_Basis_string uw_Basis_requestHeader(uw_context ctx, uw_Basis_string h) { uw_Basis_string uw_Basis_get_cookie(uw_context ctx, uw_Basis_string c) { int len = strlen(c); - char *s = ctx->headers, *p; + char *s = ctx->headers, *p = ctx->outHeaders; + + while (p = strstr(p, "\nSet-Cookie: ")) { + char *p2; + p += 13; + p2 = strchr(p, '='); + + if (p2) { + size_t sz = strcspn(p2+1, ";\r\n"); + + if (!strncasecmp(p, c, p2 - p)) { + char *ret = uw_malloc(ctx, sz + 1); + memcpy(ret, p2+1, sz); + ret[sz] = 0; + return ret; + } + } + } while (p = strchr(s, ':')) { if (!strncasecmp(s, "Cookie: ", 8) && !strncmp(p + 2, c, len) -- cgit v1.2.3