From 7dcb4eeaa6f3fa9583c46f47c8f2302285a0f7f6 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sat, 4 Jan 2020 15:28:42 +0000 Subject: [PATCH] reverse-proxy: allow proxying rfc8441 ws CONNECT Take the opportunity to provide public method index constants --- include/libwebsockets/lws-http.h | 24 +++++++++++++----------- lib/roles/ws/server-ws.c | 4 +++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/include/libwebsockets/lws-http.h b/include/libwebsockets/lws-http.h index d19e5aa6f..e1c14e8a3 100644 --- a/include/libwebsockets/lws-http.h +++ b/include/libwebsockets/lws-http.h @@ -620,6 +620,18 @@ lws_add_http_common_headers(struct lws *wsi, unsigned int code, const char *content_type, lws_filepos_t content_len, unsigned char **p, unsigned char *end); +enum { + LWSHUMETH_GET, + LWSHUMETH_POST, + LWSHUMETH_OPTIONS, + LWSHUMETH_PUT, + LWSHUMETH_PATCH, + LWSHUMETH_DELETE, + LWSHUMETH_CONNECT, + LWSHUMETH_HEAD, + LWSHUMETH_COLON_PATH, +}; + /** * lws_http_get_uri_and_method() - Get information on method and url * @@ -627,17 +639,7 @@ lws_add_http_common_headers(struct lws *wsi, unsigned int code, * \param puri_ptr: points to pointer to set to url * \param puri_len: points to int to set to uri length * - * Returns -1 or method index - * - * GET 0 - * POST 1 - * OPTIONS 2 - * PUT 3 - * PATCH 4 - * DELETE 5 - * CONNECT 6 - * HEAD 7 - * :path 8 + * Returns -1 or method index as one of the LWSHUMETH_ constants * * If returns method, *puri_ptr is set to the method's URI string and *puri_len * to its length diff --git a/lib/roles/ws/server-ws.c b/lib/roles/ws/server-ws.c index 862564e3d..6f3194ffd 100644 --- a/lib/roles/ws/server-ws.c +++ b/lib/roles/ws/server-ws.c @@ -465,7 +465,9 @@ lws_process_ws_upgrade(struct lws *wsi) meth = lws_http_get_uri_and_method(wsi, &uri_ptr, &uri_len); hit = lws_find_mount(wsi, uri_ptr, uri_len); - if (hit && (meth == 0 || meth == 8) && + if (hit && (meth == LWSHUMETH_GET || + meth == LWSHUMETH_CONNECT || + meth == LWSHUMETH_COLON_PATH) && (hit->origin_protocol == LWSMPRO_HTTPS || hit->origin_protocol == LWSMPRO_HTTP)) /*