[Libwebsockets] Need to send additional headers from websockets client to server

Andy Green andy at warmcat.com
Sat Jan 9 20:31:05 CET 2016

On January 10, 2016 2:17:58 AM GMT+08:00, Mark Goldman <mgoldman at securityevaluators.com> wrote:
>I've been trying to figure out how my websockets client can send an
>additional header to the server but I can't seem to find any guidance.
>After looking through the code, it appears that there isn't a way to
>get an additional header in from the client side, is this correct?

No, you get a user callback LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER to protocols[0], after the connect but before sending the upgrade request, where you can stick cookies in or whatever.

For that callback the in parameter is a char ** pointing to the header buffer you may add up to len chars to.  *p must be set to the end of what you added.

   char **p = (char **)in;

   if (len < 20)
      return 1;

   *p += sprintf(*p, "myheader: awesome\r\n");

Watch out though user data has not been allocated and is NULL.


>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org

More information about the Libwebsockets mailing list