[Libwebsockets] libwebsocket_write & LWS_WRITE_HTTP_HEADERS

Micka mickamusset at gmail.com
Tue Dec 30 17:33:31 CET 2014


Hi,

can someone check if it's done correctly ?

I want to check if i've implemented correctly the set cookie header ?

static unsigned char buffer[4096];

p = buffer + LWS_SEND_BUFFER_PRE_PADDING;
end = p + sizeof(buffer) - LWS_SEND_BUFFER_PRE_PADDING;
// send header :
if (lws_add_http_header_status(this, wsi, 200, &p, end))
return 1;
if (lws_add_http_header_by_token(this, wsi,
WSI_TOKEN_HTTP_SERVER,
(unsigned char *)"libwebsockets",
13, &p, end))
return 1;

if (lws_add_http_header_by_token(this, wsi,
WSI_TOKEN_HTTP_CONTENT_TYPE,
(unsigned char *)"application/json",
10, &p, end))
return 1;
n = sprintf(acCookieParam, "key=%s;Max-Age=%d", acKey, WEB_COOKIE_LIFE);

if (lws_add_http_header_by_name(this, wsi,
(unsigned char *)"set-cookie:",
(unsigned char *)acCookieParam, n, &p, end))
return 1;

if (lws_finalize_http_header(this, wsi, &p, end))
return 1;
 n = libwebsocket_write(wsi,
buffer + LWS_SEND_BUFFER_PRE_PADDING,
p - (buffer + LWS_SEND_BUFFER_PRE_PADDING),
LWS_WRITE_HTTP_HEADERS);
 libwebsocket_callback_on_writable(this, wsi);


Thx,
Micka.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libwebsockets.org/pipermail/libwebsockets/attachments/20141230/5bd1c441/attachment.html>


More information about the Libwebsockets mailing list