[Libwebsockets] lws_client_connect_via_info() - protocol 0 handler

Andy Green andy at warmcat.com
Wed Feb 15 02:18:02 CET 2017

On 02/15/2017 01:50 AM, Joel Winarske wrote:
> Hi Andy,
> How do I override the http client protocol handler in the case of lwsws?

It looks like it should ideally be done by setting the .vhost and the 
.protocol name in the connect info.  But not supported until now.

> When I set info.protocol to my protocol name, it has no effect.
> In lws_client_connect_via_info() I see the following; which for lwsws 
> assigns it to "http-only":
> wsi->protocol = &wsi->vhost->protocols[0];

That doesn't mean much though since it knows it will generate callbacks 
in the process of connecting, and when no better protocol is capable of 
being selected (because for ws it must be negotiated with the server), 
lws uses protocols[0] for want of anything better in many places.

Client connections were until recently all ws/wss, for that this will 
work fine since the protocol is negotiated and selected later.

For HTTP[S] client until now no code to allow forcing the protocol 
selection... that works fine with all on protocols[0] in "by hand" code 
like the original test server.  But being able to target a specific 
plugin / protocol handler by name makes a lot more sense inside lwsws.

Please try this


pushed on master just now.

Set the info .vhost, the protocol name you want on that vhost in the 
info .protocol and there should be an info.method set already indicating 
http GET or whatever.  Then it will attempt to select the protocol from 
the vhost early in the connection action.


> Thanks,
> Joel
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets

More information about the Libwebsockets mailing list