From 19895bcfd4e89f96100ab2dca041e965973f8e2b Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sat, 9 Nov 2013 11:59:56 +0800 Subject: [PATCH] introduce LWS_CALLBACK_FILTER_HTTP_CONNECTION Signed-off-by: Andy Green --- lib/handshake.c | 5 +++++ lib/libwebsockets.h | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/handshake.c b/lib/handshake.c index 3e1941cf..f1e7dadb 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -145,6 +145,11 @@ libwebsocket_read(struct libwebsocket_context *context, n = 0; if (wsi->protocol->callback) + n = wsi->protocol->callback(context, wsi, + LWS_CALLBACK_FILTER_HTTP_CONNECTION, + wsi->user_space, uri_ptr, uri_len); + + if (!n && wsi->protocol->callback) n = wsi->protocol->callback(context, wsi, LWS_CALLBACK_HTTP, wsi->user_space, uri_ptr, uri_len); diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 5cade285..54d485ab 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -148,6 +148,7 @@ enum libwebsocket_callback_reasons { LWS_CALLBACK_HTTP_FILE_COMPLETION, LWS_CALLBACK_HTTP_WRITEABLE, LWS_CALLBACK_FILTER_NETWORK_CONNECTION, + LWS_CALLBACK_FILTER_HTTP_CONNECTION, LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION, LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS, LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS, @@ -492,6 +493,18 @@ struct libwebsocket_extension; * Because this happens immediately after the network connection * from the client, there's no websocket protocol selected yet so * this callback is issued only to protocol 0. + * + * LWS_CALLBACK_FILTER_HTTP_CONNECTION: called when the request 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 URI, eg, "/" + * 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 http + * connection to proceed or to kill the connection. * * LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: called when the handshake has * been received and parsed from the client, but the response is