[core] convenience macros to check req methods
This commit is contained in:
parent
27e27e5e40
commit
19985261b2
|
@ -156,9 +156,6 @@ const buffer * strftime_cache_get(const time_t last_mod) {
|
|||
|
||||
int http_response_handle_cachable(connection *con, const buffer *mtime) {
|
||||
const buffer *vb;
|
||||
int head_or_get =
|
||||
( HTTP_METHOD_GET == con->request.http_method
|
||||
|| HTTP_METHOD_HEAD == con->request.http_method);
|
||||
|
||||
/*
|
||||
* 14.26 If-None-Match
|
||||
|
@ -177,7 +174,7 @@ int http_response_handle_cachable(connection *con, const buffer *mtime) {
|
|||
&& (200 == con->http_status || 0 == con->http_status)
|
||||
&& NULL != http_header_request_get(con, HTTP_HEADER_RANGE, CONST_STR_LEN("Range")));
|
||||
if (etag_is_equal(con->physical.etag, vb->ptr, !range_request)) {
|
||||
if (head_or_get) {
|
||||
if (http_method_get_or_head(con->request.http_method)) {
|
||||
con->http_status = 304;
|
||||
return HANDLER_FINISHED;
|
||||
} else {
|
||||
|
@ -186,7 +183,7 @@ int http_response_handle_cachable(connection *con, const buffer *mtime) {
|
|||
return HANDLER_FINISHED;
|
||||
}
|
||||
}
|
||||
} else if (head_or_get
|
||||
} else if (http_method_get_or_head(con->request.http_method)
|
||||
&& (vb = http_header_request_get(con, HTTP_HEADER_IF_MODIFIED_SINCE, CONST_STR_LEN("If-Modified-Since")))) {
|
||||
/* last-modified handling */
|
||||
size_t used_len;
|
||||
|
|
|
@ -65,5 +65,7 @@ int get_http_version_key(const char *s, size_t slen);
|
|||
http_method_t get_http_method_key(const char *s, size_t slen);
|
||||
void http_status_append(buffer *b, int status);
|
||||
void http_method_append(buffer *b, http_method_t method);
|
||||
#define http_method_get_or_head(method) ((method) <= HTTP_METHOD_HEAD)
|
||||
#define http_method_get_head_post(method) ((method) <= HTTP_METHOD_POST)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1147,8 +1147,7 @@ CONNECTION_FUNC(mod_deflate_handle_response_start) {
|
|||
&& if_none_match->ptr[etaglen-1] == '-'
|
||||
&& 0 == strncmp(if_none_match->ptr+etaglen, label, strlen(label))) {
|
||||
|
||||
if ( HTTP_METHOD_GET == con->request.http_method
|
||||
|| HTTP_METHOD_HEAD == con->request.http_method) {
|
||||
if (http_method_get_or_head(con->request.http_method)) {
|
||||
/* modify ETag response header in-place to remove '"' and append '-label"' */
|
||||
vb->ptr[etaglen-1] = '-'; /*(overwrite end '"')*/
|
||||
buffer_append_string(vb, label);
|
||||
|
|
|
@ -1026,20 +1026,11 @@ URIHANDLER_FUNC(mod_dirlisting_subrequest) {
|
|||
plugin_data *p = p_d;
|
||||
stat_cache_entry *sce = NULL;
|
||||
|
||||
/* we only handle GET and HEAD */
|
||||
switch(con->request.http_method) {
|
||||
case HTTP_METHOD_GET:
|
||||
case HTTP_METHOD_HEAD:
|
||||
break;
|
||||
default:
|
||||
return HANDLER_GO_ON;
|
||||
}
|
||||
|
||||
if (con->mode != DIRECT) return HANDLER_GO_ON;
|
||||
|
||||
if (buffer_is_empty(con->physical.path)) return HANDLER_GO_ON;
|
||||
if (buffer_is_empty(con->uri.path)) return HANDLER_GO_ON;
|
||||
if (con->uri.path->ptr[buffer_string_length(con->uri.path) - 1] != '/') return HANDLER_GO_ON;
|
||||
if (!http_method_get_or_head(con->request.http_method)) return HANDLER_GO_ON;
|
||||
if (buffer_is_empty(con->physical.path)) return HANDLER_GO_ON;
|
||||
|
||||
mod_dirlisting_patch_config(con, p);
|
||||
|
||||
|
|
|
@ -275,8 +275,7 @@ CONNECTION_FUNC(mod_expire_handler) {
|
|||
/* Add caching headers only to http_status 200 OK or 206 Partial Content */
|
||||
if (con->http_status != 200 && con->http_status != 206) return HANDLER_GO_ON;
|
||||
/* Add caching headers only to GET or HEAD requests */
|
||||
if ( con->request.http_method != HTTP_METHOD_GET
|
||||
&& con->request.http_method != HTTP_METHOD_HEAD) return HANDLER_GO_ON;
|
||||
if (!http_method_get_or_head(con->request.http_method)) return HANDLER_GO_ON;
|
||||
/* Add caching headers only if not already present */
|
||||
vb = http_header_response_get(con, HTTP_HEADER_CACHE_CONTROL, CONST_STR_LEN("Cache-Control"));
|
||||
if (NULL != vb) return HANDLER_GO_ON;
|
||||
|
|
|
@ -859,8 +859,7 @@ static handler_t proxy_create_env(gw_handler_ctx *gwhctx) {
|
|||
|
||||
if (con->request.content_length > 0
|
||||
|| (0 == con->request.content_length
|
||||
&& HTTP_METHOD_GET != con->request.http_method
|
||||
&& HTTP_METHOD_HEAD != con->request.http_method)) {
|
||||
&& !http_method_get_or_head(con->request.http_method))) {
|
||||
/* set Content-Length if client sent Transfer-Encoding: chunked
|
||||
* and not streaming to backend (request body has been fully received) */
|
||||
const buffer *vb = http_header_request_get(con, HTTP_HEADER_CONTENT_LENGTH, CONST_STR_LEN("Content-Length"));
|
||||
|
|
|
@ -106,14 +106,7 @@ URIHANDLER_FUNC(mod_staticfile_subrequest) {
|
|||
if (con->mode != DIRECT) return HANDLER_GO_ON;
|
||||
|
||||
/* we only handle GET, POST and HEAD */
|
||||
switch(con->request.http_method) {
|
||||
case HTTP_METHOD_GET:
|
||||
case HTTP_METHOD_POST:
|
||||
case HTTP_METHOD_HEAD:
|
||||
break;
|
||||
default:
|
||||
return HANDLER_GO_ON;
|
||||
}
|
||||
if (!http_method_get_head_post(con->request.http_method)) return HANDLER_GO_ON;
|
||||
|
||||
mod_staticfile_patch_config(con, p);
|
||||
|
||||
|
|
|
@ -855,8 +855,7 @@ int http_request_parse(connection * const con, char * const hdrs, const unsigned
|
|||
http_header_request_unset(con, HTTP_HEADER_CONTENT_LENGTH, CONST_STR_LEN("Content-Length"));
|
||||
}
|
||||
}
|
||||
if ((HTTP_METHOD_GET == con->request.http_method
|
||||
|| HTTP_METHOD_HEAD == con->request.http_method)
|
||||
if (http_method_get_or_head(con->request.http_method)
|
||||
&& !(con->conf.http_parseopts & HTTP_PARSEOPT_METHOD_GET_BODY)) {
|
||||
return http_request_header_line_invalid(con, 400, "GET/HEAD with content-length -> 400");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue