diff --git a/examples/device-dashboard/net.c b/examples/device-dashboard/net.c index f38b5578..968e0f1a 100644 --- a/examples/device-dashboard/net.c +++ b/examples/device-dashboard/net.c @@ -123,18 +123,20 @@ static struct user *authenticate(struct mg_http_message *hm) { static void handle_login(struct mg_connection *c, struct user *u) { char cookie[256]; mg_snprintf(cookie, sizeof(cookie), - "Set-Cookie: access_token=%s;Path=/;" - "HttpOnly;SameSite=Lax;Max-Age=%d\r\n", - u->access_token, 3600 * 24); + "Set-Cookie: access_token=%s; Path=/; " + "%sHttpOnly; SameSite=Lax; Max-Age=%d\r\n", + u->access_token, c->is_tls ? "Secure; " : "", 3600 * 24); mg_http_reply(c, 200, cookie, "{%m:%m}", MG_ESC("user"), MG_ESC(u->name)); } static void handle_logout(struct mg_connection *c) { - mg_http_reply(c, 200, - "Set-Cookie: access_token=; Path=/; " - "Expires=Thu, 01 Jan 1970 00:00:00 UTC; " - "Secure; HttpOnly; Max-Age=0; \r\n", - "true\n"); + char cookie[256]; + mg_snprintf(cookie, sizeof(cookie), + "Set-Cookie: access_token=; Path=/; " + "Expires=Thu, 01 Jan 1970 00:00:00 UTC; " + "%sHttpOnly; Max-Age=0; \r\n", + c->is_tls ? "Secure; " : ""); + mg_http_reply(c, 200, cookie, "true\n"); } static void handle_debug(struct mg_connection *c, struct mg_http_message *hm) {