[Libwebsockets] Websocket header verification
andy at warmcat.com
Thu Jan 19 11:01:00 CET 2017
On 01/19/2017 05:39 PM, techi eth wrote:
> Thanks for quick answer.
> Yes,I was looking before wsupgrade.
> Is their any possibility to send user specific code (The way we send
> with close connection) so that client will know reason for disconnection.
At that time the upgrade hasn't happened and you are still speaking HTTP.
* lws_return_http_status() - Return simple http status
* \param wsi: Websocket instance (available from user callback)
* \param code: Status index, eg, 404
* \param html_body: User-readable HTML description < 1KB, or NULL
* Helper to report HTTP errors back to the client cleanly and
LWS_VISIBLE LWS_EXTERN int
lws_return_http_status(struct lws *wsi, unsigned int code,
const char *html_body);
After that you should just end with
> On Thu, Jan 19, 2017 at 2:59 PM, Andy Green <andy at warmcat.com
> <mailto:andy at warmcat.com>> wrote:
> On 01/19/2017 05:21 PM, techi eth wrote:
> Is it possible to check Header before accepting client
> connection with libwebsocket ?
> Depends what you mean by "accept"... tcp accept, no, because you
> have to make the tcp connection to get the headers.
> Accept to perform the ws upgrade... sure...
> LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION = 20,
> /**< called when the handshake has
> * been received and parsed from the client, but the response is
> * not sent yet. Return non-zero to disallow the connection.
> * user is a pointer to the connection user space allocation,
> * in is the requested protocol name
> * In your handler you can use the public APIs
> * lws_hdr_total_length() / lws_hdr_copy() to access all of the
> * headers using the header enums lws_token_indexes from
> * libwebsockets.h to check for and read the supported header
> * presence and content before deciding to allow the handshake
> * to proceed or to kill the connection. */
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> <mailto:Libwebsockets at ml.libwebsockets.org>
More information about the Libwebsockets