diff options
author | Luciano Iam <lucianito@gmail.com> | 2020-02-26 23:09:59 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2020-02-27 03:42:54 +0100 |
commit | ec8e0f8ee50de92c10d1d97c136f4f0dbd0a26e0 (patch) | |
tree | d2f46cafe22cb90b94a5533b947e5ae01484fb9d /libs/surfaces/websockets/server.cc | |
parent | bc2cbfc7ec044692e959d5d1e55f5ea4fc76fe85 (diff) |
Gracefully reject HTTP requests reaching the websockets surface
Diffstat (limited to 'libs/surfaces/websockets/server.cc')
-rw-r--r-- | libs/surfaces/websockets/server.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libs/surfaces/websockets/server.cc b/libs/surfaces/websockets/server.cc index 88984348c8..e91acb717a 100644 --- a/libs/surfaces/websockets/server.cc +++ b/libs/surfaces/websockets/server.cc @@ -295,6 +295,14 @@ WebsocketsServer::write_client (Client wsi) } } +void +WebsocketsServer::reject_http_client (Client wsi) +{ + const char *html_body = "<p>This URL is not meant to be accessed via HTTP; for example using" + " a web browser. Refer to Ardour documentation for further information.</p>"; + lws_return_http_status (wsi, 404, html_body); +} + bool WebsocketsServer::io_handler (Glib::IOCondition ioc, lws_sockfd_type fd) { @@ -388,6 +396,10 @@ WebsocketsServer::lws_callback (struct lws* wsi, enum lws_callback_reasons reaso server->write_client (wsi); break; + case LWS_CALLBACK_HTTP: + server->reject_http_client (wsi); + break; + case LWS_CALLBACK_FILTER_NETWORK_CONNECTION: case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: case LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED: @@ -398,6 +410,10 @@ WebsocketsServer::lws_callback (struct lws* wsi, enum lws_callback_reasons reaso case LWS_CALLBACK_LOCK_POLL: case LWS_CALLBACK_UNLOCK_POLL: case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: + case LWS_CALLBACK_FILTER_HTTP_CONNECTION: + case LWS_CALLBACK_HTTP_BIND_PROTOCOL: + case LWS_CALLBACK_ADD_HEADERS: + case LWS_CALLBACK_HTTP_CONFIRM_UPGRADE: break; /* TODO: handle HTTP connections. |