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

Mark Goldman mgoldman at securityevaluators.com
Sat Jan 9 21:05:36 CET 2016


After looking closer at the code and the API documentation, I see that
I missed that this was funneled through protocol[0].  Sorry for the
ID10T error.

Would there be any harm in the client looking in the protocols array
so the "correct" callback can be used for client connects the that
should be known at libwebsocket_client_connect() time?  I feel like
that would be less surprising for client users that have multiple
protocols.

Also, thank you.

-mdg

On Sat, Jan 9, 2016 at 2:31 PM, Andy Green <andy at warmcat.com> wrote:
>
>
> 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.
>
> case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER:
> {
>    char **p = (char **)in;
>
>    if (len < 20)
>       return 1;
>
>    *p += sprintf(*p, "myheader: awesome\r\n");
> }
> break;
>
> Watch out though user data has not been allocated and is NULL.
>
> -Andy
>
>>-mdg
>>_______________________________________________
>>Libwebsockets mailing list
>>Libwebsockets at ml.libwebsockets.org
>>http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>



More information about the Libwebsockets mailing list