kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 36e99072f3784a81a791ea5e908668cb923024c8
parent 8b9ea825ebd892f7156340b6b1d09971675f8d11
Author: Joris Vink <joris@coders.se>
Date:   Tue,  7 Feb 2017 22:04:00 +0100

cookie example improvements.

Diffstat:
examples/cookies/conf/cookies.conf | 7+------
examples/cookies/src/example.c | 36+++++++++++++++++-------------------
2 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/examples/cookies/conf/cookies.conf b/examples/cookies/conf/cookies.conf @@ -5,16 +5,11 @@ load ./cookies.so tls_dhparam dh2048.pem -http_body_max 1024000000 -http_body_disk_offload 1024000 - - domain 127.0.0.1 { certfile cert/server.crt certkey cert/server.key - accesslog kore_access.log - static / serve_cookies + static / serve_cookies static /secure serve_cookies static /vault serve_cookies } diff --git a/examples/cookies/src/example.c b/examples/cookies/src/example.c @@ -30,34 +30,33 @@ int serve_cookies(struct http_request *); int serve_cookies(struct http_request *req) { - char *read; - struct http_cookie *complex; + char *read; + struct http_cookie *cookie; http_populate_cookies(req); - if (http_request_cookie(req, "Simple", &read)) { + + if (http_request_cookie(req, "Simple", &read)) kore_log(LOG_DEBUG, "Got simple: %s", read); - } - if (http_request_cookie(req, "Complex", &read)) { + if (http_request_cookie(req, "Complex", &read)) kore_log(LOG_DEBUG, "Got complex: %s", read); - } - if (http_request_cookie(req, "Formatted", &read)) { + if (http_request_cookie(req, "Formatted", &read)) kore_log(LOG_DEBUG, "Got formatted: %s", read); - } /* set simple cookie */ - http_response_cookie(req, "Simple", "Hello World!", HTTP_COOKIE_DEFAULT); + http_response_cookie(req, "Simple", "Hello World!", 0); /* set complex cookie */ - complex = http_response_cookie(req, "Complex", "Secure Value!", - HTTP_COOKIE_HTTPONLY | HTTP_COOKIE_SECURE); - complex->path = kore_strdup("/secure"); - complex->expires = time(NULL) + 1 * 60 * 60; - complex->domain = kore_strdup("127.0.0.1"); + cookie = http_response_cookie(req, "Complex", "Secure Value!", + HTTP_COOKIE_HTTPONLY | HTTP_COOKIE_SECURE); + cookie ->path = kore_strdup("/secure"); + cookie->expires = time(NULL) + 1 * 60 * 60; + cookie->domain = kore_strdup(req->host); /* set formatted cookie */ - http_response_header(req, "set-cookie", - "Formatted=TheValue; Path=/vault; HttpOnly"); + http_response_header(req, "set-cookie", + "Formatted=TheValue; Path=/vault; HttpOnly"); http_response(req, 200, html, strlen(html)); - return KORE_RESULT_OK; -}- \ No newline at end of file + + return (KORE_RESULT_OK); +}