From a60e60bc297013e8bf27f2be9bc7d5f221d40140 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Thu, 1 Aug 2019 12:56:29 +0100 Subject: [PATCH] http: server: support HEAD via mount Until now we parse HEAD requests but don't properly fulfil them. This adds enough that if the request pointed to a valid mount, it will send the headers and complete the transaction without sending the body. Test with $ (echo -n -e "GET / HTTP/1.0\r\nHost: default\r\n\r\n"; sleep 2) | nc 127.0.0.1 7681 --- lib/roles/http/server/server.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index a2465e77d..3ecda733d 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -767,6 +767,7 @@ lws_find_mount(struct lws *wsi, const char *uri_ptr, int uri_len) ((hm->origin_protocol == LWSMPRO_CGI || lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) || lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI) || + lws_hdr_total_length(wsi, WSI_TOKEN_HEAD_URI) || (wsi->http2_substream && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH)) || @@ -2564,6 +2565,14 @@ lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, wsi->http.filepos = 0; lwsi_set_state(wsi, LRS_ISSUING_FILE); + if (lws_hdr_total_length(wsi, WSI_TOKEN_HEAD_URI)) { + /* we do not emit the body */ + if (lws_http_transaction_completed(wsi)) + return -1; + + return 0; + } + lws_callback_on_writable(wsi); return 0;