| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include <kore/kore.h> |
| 18 |
#include <kore/http.h> |
| 19 |
|
| 20 |
static char *html = "<html><body><h1>Reload this page</h1></body></html>"; |
| 21 |
|
| 22 |
int serve_cookies(struct http_request *); |
| 23 |
|
| 24 |
int |
| 25 |
serve_cookies(struct http_request *req) |
| 26 |
{ |
| 27 |
char *value; |
| 28 |
struct http_cookie *cookie; |
| 29 |
|
| 30 |
http_populate_cookies(req); |
| 31 |
|
| 32 |
if (http_request_cookie(req, "Simple", &value)) |
| 33 |
kore_log(LOG_DEBUG, "Got simple: %s", value); |
| 34 |
if (http_request_cookie(req, "Complex", &value)) |
| 35 |
kore_log(LOG_DEBUG, "Got complex: %s", value); |
| 36 |
if (http_request_cookie(req, "Formatted", &value)) |
| 37 |
kore_log(LOG_DEBUG, "Got formatted: %s", value); |
| 38 |
|
| 39 |
|
| 40 |
http_response_cookie(req, "Simple", "Hello World!", |
| 41 |
req->path, 0, 0, NULL); |
| 42 |
|
| 43 |
|
| 44 |
http_response_cookie(req, "Complex", "Secure Value!", "/secure", |
| 45 |
time(NULL) + (1 * 60 * 60), 0, NULL); |
| 46 |
|
| 47 |
|
| 48 |
http_response_cookie(req, "key", "value", req->path, 0, 60, &cookie); |
| 49 |
cookie->flags &= ~HTTP_COOKIE_HTTPONLY; |
| 50 |
|
| 51 |
|
| 52 |
http_response_header(req, "set-cookie", |
| 53 |
"Formatted=TheValue; Path=/vault; HttpOnly"); |
| 54 |
|
| 55 |
http_response(req, 200, html, strlen(html)); |
| 56 |
|
| 57 |
return (KORE_RESULT_OK); |
| 58 |
} |