[Libwebsockets] libwebsockets HTTP mode lacks LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION
"Andy Green (林安廸)"
andy at warmcat.com
Sun Nov 10 08:40:29 CET 2013
On 09/11/13 18:29, the mail apparently from Johan Lindh included:
> Good work. Seems to work fine. I'm evaluating websocketpp alongside
> with libwebsockets and pion. While pion is a fully featured HTTP
> server and very fast, unfortunately it has no WebSocket support and no
> apparent easy way to add it.
> In case you're interested, here's the current benchmarks, from slowest
> to fastest, serving a static HTML file over 10 concurrent connections.
> It's an apples-to-oranges comparison since pion is HTTP-only and
> multithreaded to boot, but pion is a good benchmark for how fast you
> can get serving HTTP with no shortcuts taken (as in, all headers fully
> supported and HTTP/1.1).
> websocketpp 0.3.0-alpha4:
> Time per request: 0.334 [ms] (mean, across all concurrent requests)
> Transfer rate: 5658.60 [Kbytes/sec] received
> libwebsockets HEAD revision:
> Time per request: 0.213 [ms] (mean, across all concurrent requests)
> Transfer rate: 8508.20 [Kbytes/sec] received
> pion 5.0.4:
> Time per request: 0.158 [ms] (mean, across all concurrent requests)
> Transfer rate: 11745.94 [Kbytes/sec] received
> Considering that libwebsockets is a fraction of pion's size and has
> WebSockets, it's looking very good indeed.
Yes, you don't say how many cores pion is running on, it'd be
interesting to restrict it to 1 and see what happens, or conversely
instantiate n lws instances on different ports and round-robin between
> You're missing a URL decoder though, so let me offer my own. It's
> quite fast and also does path normalization so you can ease up on the
> hardcore whitelisting in the test server. :-)
I implemented hopefully the same function in lws state machine style
> On Sat, Nov 9, 2013 at 5:08 AM, "Andy Green (林安廸)" <andy at warmcat.com> wrote:
>> On 09/11/13 08:28, the mail apparently from "Andy Green (林安廸)" included:
>>> On 09/11/13 02:40, the mail apparently from Johan Lindh included:
>>>> Not having access to any client headers except the URI is unacceptable
>>> You don't have to accept it ^^
>>>> in LWS_CALLBACK_HTTP, and current HEAD in git does not issue
>>>> WS_CALLBACK_FILTER_PROTOCOL_CONNECTION for HTTP connections.
>>> I can see it would be useful to do something, but we need to add an enum
>>> then, since that one is specifically when a websocket protocol
>>> connection has been made.
>>>> Additionally, I strongly suggest adding "Accept:" and
>>>> "If-Modified-Since:" to minilex.c - not being able to safely gzip or
>>>> do basic cache handling cripples performance.
>>> More headers sounds reasonable. At the moment its focus as you might
>>> guess from the name is serving websocket protocol not http. But the
>>> http stuff could indeed cope with more things.
>>> Are there any other headers people are interested in processing and
>>> having available inside libwebsockets? They'd be handled for both pure
>>> http and if they were present during the upgrade handshake. It's easier
>>> to do them all at once since fiddling with minilex isn't simple (which
>>> is why it got left to me I guess).
>> I found myself with some free time thismorning.
>> Additional headers supported in minilex + lws
>> introduce LWS_CALLBACK_FILTER_HTTP_CONNECTION
>> Fix ability to access headers in HTTP service
>> Add example code to test server for Cookies
>>>> Patch for lib/handshake.c attached.
>>> diff --git a/lib/handshake.c b/lib/handshake.c
>>> index 3007426..00e3bc1 100644
>>> --- a/lib/handshake.c
>>> +++ b/lib/handshake.c
>>> @@ -135,6 +135,11 @@ libwebsocket_read(struct libwebsocket_context
>>> uri_ptr = lws_hdr_simple_ptr(wsi, WSI_TOKEN_GET_URI);
>>> uri_len = lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI);
>>> + if (wsi->protocol->callback &&
>>> wsi->protocol->callback(context, wsi,
>>> + LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION,
>>> + wsi->user_space, uri_ptr, uri_len))
>>> + goto bail_nuke_ah;
>>> /* union transition */
>>> memset(&wsi->u, 0, sizeof(wsi->u));
More information about the Libwebsockets