summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2021-12-16 12:56:52 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2021-12-16 12:59:16 -0500
commitcca340dd263245bdec5bcb32dce64beec9ed1afe (patch)
tree75bf1323f2d45988d799383051abff420b5ced8c /src
parentea9befb29cb7eca2a401eb045c02b288067f7513 (diff)
downloadlighttpd-git-cca340dd263245bdec5bcb32dce64beec9ed1afe.tar.gz
[core] defer retrieving Last-Modified until needed
Diffstat (limited to 'src')
-rw-r--r--src/http-header-glue.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/http-header-glue.c b/src/http-header-glue.c
index 9e536848..3f2b059d 100644
--- a/src/http-header-glue.c
+++ b/src/http-header-glue.c
@@ -180,12 +180,17 @@ const buffer * http_response_set_last_modified(request_st * const r, const unix_
}
-int http_response_handle_cachable(request_st * const r, const buffer * const lmod, const unix_time64_t lmtime) {
- if (!(r->rqst_htags
- & (light_bshift(HTTP_HEADER_IF_NONE_MATCH)
- |light_bshift(HTTP_HEADER_IF_MODIFIED_SINCE)))) {
+__attribute_pure__
+static int http_response_maybe_cachable (const request_st * const r) {
+ return (r->rqst_htags
+ & (light_bshift(HTTP_HEADER_IF_NONE_MATCH)
+ |light_bshift(HTTP_HEADER_IF_MODIFIED_SINCE)));
+}
+
+
+int http_response_handle_cachable(request_st * const r, const buffer *lmod, const unix_time64_t lmtime) {
+ if (!http_response_maybe_cachable(r))
return HANDLER_GO_ON;
- }
const buffer *vb, *etag;
@@ -217,7 +222,10 @@ int http_response_handle_cachable(request_st * const r, const buffer * const lmo
}
} else if (http_method_get_or_head(r->http_method)
&& (vb = http_header_request_get(r, HTTP_HEADER_IF_MODIFIED_SINCE,
- CONST_STR_LEN("If-Modified-Since")))) {
+ CONST_STR_LEN("If-Modified-Since")))
+ && (lmod
+ || (lmod = http_header_response_get(r, HTTP_HEADER_LAST_MODIFIED,
+ CONST_STR_LEN("Last-Modified"))))) {
/* last-modified handling */
if (buffer_is_equal(lmod, vb)
|| !http_date_if_modified_since(BUF_PTR_LEN(vb), lmtime)) {
@@ -389,17 +397,14 @@ void http_response_send_file (request_st * const r, const buffer * const path, s
}
}
- /* prepare header */
- const buffer *mtime;
- mtime = http_header_response_get(r, HTTP_HEADER_LAST_MODIFIED,
- CONST_STR_LEN("Last-Modified"));
- if (NULL == mtime) {
- mtime = http_response_set_last_modified(r, sce->st.st_mtime);
- }
+ const buffer * const lmod =
+ (!light_btst(r->resp_htags, HTTP_HEADER_LAST_MODIFIED))
+ ? http_response_set_last_modified(r, sce->st.st_mtime)
+ : NULL;
- if (HANDLER_FINISHED == http_response_handle_cachable(r, mtime, sce->st.st_mtime)) {
+ if (http_response_maybe_cachable(r)
+ && HANDLER_FINISHED == http_response_handle_cachable(r, lmod, sce->st.st_mtime))
return;
- }
}
/* if we are still here, prepare body */