diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-05-04 20:15:24 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-05-04 20:15:24 +0200 |
commit | 32a8258be78371154dd66b931a9628aad0efd337 (patch) | |
tree | 4e82cad46090a5c2375ba7e4039ead3036483c38 | |
parent | ff4d898fe6a0f082baff929087df7eb38d4e890c (diff) | |
download | busybox-w32-32a8258be78371154dd66b931a9628aad0efd337.tar.gz busybox-w32-32a8258be78371154dd66b931a9628aad0efd337.tar.bz2 busybox-w32-32a8258be78371154dd66b931a9628aad0efd337.zip |
httpd: support HEAD requests even in !CGI config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/httpd.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index 951213ec5..958b3c300 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -548,7 +548,6 @@ enum { | |||
548 | enum { | 548 | enum { |
549 | SEND_HEADERS = (1 << 0), | 549 | SEND_HEADERS = (1 << 0), |
550 | SEND_BODY = (1 << 1), | 550 | SEND_BODY = (1 << 1), |
551 | SEND_HEADERS_AND_BODY = SEND_HEADERS + SEND_BODY, | ||
552 | }; | 551 | }; |
553 | static void send_file_and_exit(const char *url, int what) NORETURN; | 552 | static void send_file_and_exit(const char *url, int what) NORETURN; |
554 | 553 | ||
@@ -2177,11 +2176,11 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2177 | #if ENABLE_FEATURE_HTTPD_CGI | 2176 | #if ENABLE_FEATURE_HTTPD_CGI |
2178 | unsigned total_headers_len; | 2177 | unsigned total_headers_len; |
2179 | #endif | 2178 | #endif |
2180 | #if ENABLE_FEATURE_HTTPD_CGI | 2179 | const char *prequest; |
2181 | static const char request_GET[] ALIGN1 = "GET"; | 2180 | static const char request_GET[] ALIGN1 = "GET"; |
2182 | static const char request_HEAD[] ALIGN1 = "HEAD"; | 2181 | static const char request_HEAD[] ALIGN1 = "HEAD"; |
2182 | #if ENABLE_FEATURE_HTTPD_CGI | ||
2183 | static const char request_POST[] ALIGN1 = "POST"; | 2183 | static const char request_POST[] ALIGN1 = "POST"; |
2184 | const char *prequest; | ||
2185 | unsigned long POST_length; | 2184 | unsigned long POST_length; |
2186 | enum CGI_type { | 2185 | enum CGI_type { |
2187 | CGI_NONE = 0, | 2186 | CGI_NONE = 0, |
@@ -2285,24 +2284,23 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2285 | #endif | 2284 | #endif |
2286 | 2285 | ||
2287 | /* Determine type of request (GET/POST/...) */ | 2286 | /* Determine type of request (GET/POST/...) */ |
2288 | #if ENABLE_FEATURE_HTTPD_CGI | ||
2289 | prequest = request_GET; | 2287 | prequest = request_GET; |
2290 | if (strcasecmp(iobuf, prequest) == 0) | 2288 | if (strcasecmp(iobuf, prequest) == 0) |
2291 | goto found; | 2289 | goto found; |
2292 | prequest = request_HEAD; | 2290 | prequest = request_HEAD; |
2293 | if (strcasecmp(iobuf, prequest) == 0) | 2291 | if (strcasecmp(iobuf, prequest) == 0) |
2294 | goto found; | 2292 | goto found; |
2293 | #if !ENABLE_FEATURE_HTTPD_CGI | ||
2294 | send_headers_and_exit(HTTP_NOT_IMPLEMENTED); | ||
2295 | #else | ||
2295 | prequest = request_POST; | 2296 | prequest = request_POST; |
2296 | if (strcasecmp(iobuf, prequest) == 0) | 2297 | if (strcasecmp(iobuf, prequest) == 0) |
2297 | goto found; | 2298 | goto found; |
2298 | /* For CGI, allow DELETE, PUT, OPTIONS, etc too */ | 2299 | /* For CGI, allow DELETE, PUT, OPTIONS, etc too */ |
2299 | prequest = alloca(16); | 2300 | prequest = alloca(16); |
2300 | safe_strncpy((char*)prequest, iobuf, 16); | 2301 | safe_strncpy((char*)prequest, iobuf, 16); |
2301 | found: | ||
2302 | #else | ||
2303 | if (strcasecmp(iobuf, "GET") != 0) | ||
2304 | send_headers_and_exit(HTTP_NOT_IMPLEMENTED); | ||
2305 | #endif | 2302 | #endif |
2303 | found: | ||
2306 | /* Copy URL to stack-allocated char[] */ | 2304 | /* Copy URL to stack-allocated char[] */ |
2307 | urlcopy = alloca((HTTP_slash - urlp) + 2 + strlen(index_page)); | 2305 | urlcopy = alloca((HTTP_slash - urlp) + 2 + strlen(index_page)); |
2308 | strcpy(urlcopy, urlp); | 2306 | strcpy(urlcopy, urlp); |
@@ -2592,13 +2590,12 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2592 | /* POST / DELETE / PUT / OPTIONS for files do not make sense */ | 2590 | /* POST / DELETE / PUT / OPTIONS for files do not make sense */ |
2593 | send_headers_and_exit(HTTP_NOT_IMPLEMENTED); | 2591 | send_headers_and_exit(HTTP_NOT_IMPLEMENTED); |
2594 | } | 2592 | } |
2595 | send_file_and_exit(tptr, | ||
2596 | (prequest != request_HEAD ? SEND_HEADERS_AND_BODY : SEND_HEADERS) | ||
2597 | ); | ||
2598 | #else | 2593 | #else |
2599 | /* It was verified earlier that it is a "GET" */ | 2594 | /* !CGI: it can be only GET or HEAD */ |
2600 | send_file_and_exit(tptr, SEND_HEADERS_AND_BODY); | ||
2601 | #endif | 2595 | #endif |
2596 | send_file_and_exit(tptr, | ||
2597 | (prequest != request_HEAD ? (SEND_HEADERS + SEND_BODY) : SEND_HEADERS) | ||
2598 | ); | ||
2602 | } | 2599 | } |
2603 | 2600 | ||
2604 | /* | 2601 | /* |