httpd: support HEAD requests even in !CGI config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
ff4d898fe6
commit
32a8258be7
@ -548,7 +548,6 @@ enum {
|
|||||||
enum {
|
enum {
|
||||||
SEND_HEADERS = (1 << 0),
|
SEND_HEADERS = (1 << 0),
|
||||||
SEND_BODY = (1 << 1),
|
SEND_BODY = (1 << 1),
|
||||||
SEND_HEADERS_AND_BODY = SEND_HEADERS + SEND_BODY,
|
|
||||||
};
|
};
|
||||||
static void send_file_and_exit(const char *url, int what) NORETURN;
|
static void send_file_and_exit(const char *url, int what) NORETURN;
|
||||||
|
|
||||||
@ -2177,11 +2176,11 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
|
|||||||
#if ENABLE_FEATURE_HTTPD_CGI
|
#if ENABLE_FEATURE_HTTPD_CGI
|
||||||
unsigned total_headers_len;
|
unsigned total_headers_len;
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_FEATURE_HTTPD_CGI
|
const char *prequest;
|
||||||
static const char request_GET[] ALIGN1 = "GET";
|
static const char request_GET[] ALIGN1 = "GET";
|
||||||
static const char request_HEAD[] ALIGN1 = "HEAD";
|
static const char request_HEAD[] ALIGN1 = "HEAD";
|
||||||
|
#if ENABLE_FEATURE_HTTPD_CGI
|
||||||
static const char request_POST[] ALIGN1 = "POST";
|
static const char request_POST[] ALIGN1 = "POST";
|
||||||
const char *prequest;
|
|
||||||
unsigned long POST_length;
|
unsigned long POST_length;
|
||||||
enum CGI_type {
|
enum CGI_type {
|
||||||
CGI_NONE = 0,
|
CGI_NONE = 0,
|
||||||
@ -2285,24 +2284,23 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Determine type of request (GET/POST/...) */
|
/* Determine type of request (GET/POST/...) */
|
||||||
#if ENABLE_FEATURE_HTTPD_CGI
|
|
||||||
prequest = request_GET;
|
prequest = request_GET;
|
||||||
if (strcasecmp(iobuf, prequest) == 0)
|
if (strcasecmp(iobuf, prequest) == 0)
|
||||||
goto found;
|
goto found;
|
||||||
prequest = request_HEAD;
|
prequest = request_HEAD;
|
||||||
if (strcasecmp(iobuf, prequest) == 0)
|
if (strcasecmp(iobuf, prequest) == 0)
|
||||||
goto found;
|
goto found;
|
||||||
|
#if !ENABLE_FEATURE_HTTPD_CGI
|
||||||
|
send_headers_and_exit(HTTP_NOT_IMPLEMENTED);
|
||||||
|
#else
|
||||||
prequest = request_POST;
|
prequest = request_POST;
|
||||||
if (strcasecmp(iobuf, prequest) == 0)
|
if (strcasecmp(iobuf, prequest) == 0)
|
||||||
goto found;
|
goto found;
|
||||||
/* For CGI, allow DELETE, PUT, OPTIONS, etc too */
|
/* For CGI, allow DELETE, PUT, OPTIONS, etc too */
|
||||||
prequest = alloca(16);
|
prequest = alloca(16);
|
||||||
safe_strncpy((char*)prequest, iobuf, 16);
|
safe_strncpy((char*)prequest, iobuf, 16);
|
||||||
found:
|
|
||||||
#else
|
|
||||||
if (strcasecmp(iobuf, "GET") != 0)
|
|
||||||
send_headers_and_exit(HTTP_NOT_IMPLEMENTED);
|
|
||||||
#endif
|
#endif
|
||||||
|
found:
|
||||||
/* Copy URL to stack-allocated char[] */
|
/* Copy URL to stack-allocated char[] */
|
||||||
urlcopy = alloca((HTTP_slash - urlp) + 2 + strlen(index_page));
|
urlcopy = alloca((HTTP_slash - urlp) + 2 + strlen(index_page));
|
||||||
strcpy(urlcopy, urlp);
|
strcpy(urlcopy, urlp);
|
||||||
@ -2592,13 +2590,12 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
|
|||||||
/* POST / DELETE / PUT / OPTIONS for files do not make sense */
|
/* POST / DELETE / PUT / OPTIONS for files do not make sense */
|
||||||
send_headers_and_exit(HTTP_NOT_IMPLEMENTED);
|
send_headers_and_exit(HTTP_NOT_IMPLEMENTED);
|
||||||
}
|
}
|
||||||
send_file_and_exit(tptr,
|
|
||||||
(prequest != request_HEAD ? SEND_HEADERS_AND_BODY : SEND_HEADERS)
|
|
||||||
);
|
|
||||||
#else
|
#else
|
||||||
/* It was verified earlier that it is a "GET" */
|
/* !CGI: it can be only GET or HEAD */
|
||||||
send_file_and_exit(tptr, SEND_HEADERS_AND_BODY);
|
|
||||||
#endif
|
#endif
|
||||||
|
send_file_and_exit(tptr,
|
||||||
|
(prequest != request_HEAD ? (SEND_HEADERS + SEND_BODY) : SEND_HEADERS)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user