From c5d69441bd43ace9d9c2b03a89aa0ed4871c288d Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Fri, 13 Mar 2020 19:32:17 +0300 Subject: [magi] Cookies almost work. --- examples/cookie.c | 6 +++++- src/response.c | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/cookie.c b/examples/cookie.c index 601c901..0492e1b 100644 --- a/examples/cookie.c +++ b/examples/cookie.c @@ -7,7 +7,11 @@ void list_cookies(magi_request *r) magi_response(r, "Cookies:"); for (current = r->cookies; current; current = current->next) { magi_cookie *c = ¤t->item; - magi_response_format(r, "
[%s] = [%s]", c->name, c->data); + magi_response(r, "
["); + magi_response(r, c->name); + magi_response(r, "] = ["); + magi_response(r, c->data); + magi_response(r, "]"); } } diff --git a/src/response.c b/src/response.c index f7a6f67..400080a 100644 --- a/src/response.c +++ b/src/response.c @@ -27,11 +27,18 @@ void magi_response_status(magi_request *r, int code, const char *description) void magi_response_cookie(magi_request *r, const char *name, const char *data) { magi_param addon; + int nlen; + int dlen; if (r->response->head_done) { return; } + nlen = strlen(name); + dlen = strlen(data); addon.name = magi_str_create_copy("Set-Cookie", 10); - /* TODO */ + addon.data = malloc(nlen + dlen + 2); + memcpy(addon.data, name, nlen); + addon.data[nlen] = '='; + memcpy(addon.data + nlen + 1, data, dlen + 1); magi_params_add(&r->response->head_general, &addon); } -- cgit v1.2.3