summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2019-12-10 00:38:47 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2019-12-10 00:38:47 -0500
commit2ae9001fc0b6a1df9a13bfe5a64b600474d1532e (patch)
treed8f3ad8f2f4dfa5063d3b1af05ccd70c17743cd7
parentd6b41bea6a060efc734a8946c2b3ff99b7e041a5 (diff)
downloadlighttpd1.4-personal/gstrauss/master.tar.gz
lighttpd1.4-personal/gstrauss/master.zip
[core] convenience macros to check req methodspersonal/gstrauss/master
-rw-r--r--src/http-header-glue.c7
-rw-r--r--src/http_kv.h2
-rw-r--r--src/mod_deflate.c3
-rw-r--r--src/mod_dirlisting.c13
-rw-r--r--src/mod_expire.c3
-rw-r--r--src/mod_proxy.c3
-rw-r--r--src/mod_staticfile.c9
-rw-r--r--src/request.c3
8 files changed, 11 insertions, 32 deletions
diff --git a/src/http-header-glue.c b/src/http-header-glue.c
index 2e18e4d7..515a4eb2 100644
--- a/src/http-header-glue.c
+++ b/src/http-header-glue.c
@@ -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;
diff --git a/src/http_kv.h b/src/http_kv.h
index 8b73d7b2..73d0e750 100644
--- a/src/http_kv.h
+++ b/src/http_kv.h
@@ -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
diff --git a/src/mod_deflate.c b/src/mod_deflate.c
index ee3cd841..f6576e4a 100644
--- a/src/mod_deflate.c
+++ b/src/mod_deflate.c
@@ -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);
diff --git a/src/mod_dirlisting.c b/src/mod_dirlisting.c
index 703d212c..e98d791c 100644
--- a/src/mod_dirlisting.c
+++ b/src/mod_dirlisting.c
@@ -1023,20 +1023,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);
diff --git a/src/mod_expire.c b/src/mod_expire.c
index c80cc81b..efb58888 100644
--- a/src/mod_expire.c
+++ b/src/mod_expire.c
@@ -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;
diff --git a/src/mod_proxy.c b/src/mod_proxy.c
index 20e1b0ea..ff57c32d 100644
--- a/src/mod_proxy.c
+++ b/src/mod_proxy.c
@@ -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"));
diff --git a/src/mod_staticfile.c b/src/mod_staticfile.c
index d3310525..b14ff826 100644
--- a/src/mod_staticfile.c
+++ b/src/mod_staticfile.c
@@ -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);
diff --git a/src/request.c b/src/request.c
index 97c05584..e0ad85c8 100644
--- a/src/request.c
+++ b/src/request.c
@@ -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");
}