summaryrefslogtreecommitdiff
path: root/src/c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-11-08 10:46:14 -0500
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-11-08 10:46:14 -0500
commit44db3e6164b414f4724c9971fe550036ebb706c3 (patch)
treedbb9e543c0deb0ef4bcb65308bc4f75f408cb4df /src/c
parent443e2b566220b4aa3921527742e1efbabc0eb0e3 (diff)
[getCookie] reads cookie settings from current page generation
Diffstat (limited to 'src/c')
-rw-r--r--src/c/urweb.c20
1 files changed, 19 insertions, 1 deletions
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)