[PATCH 3/6] httpd: Match If-Modified-Since only when If-None-Match is not present
Sergey Ponomarev
stokito at gmail.com
Sat Jan 9 21:09:48 UTC 2021
It doesn't make sense to check If-Modified-Since if If-None-Match has a value but wasn't matched.
https://tools.ietf.org/html/rfc7232#section-3.3
Signed-off-by: Sergey Ponomarev <stokito at gmail.com>
---
networking/httpd.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/networking/httpd.c b/networking/httpd.c
index 6cd40c13b..93db24f25 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1791,19 +1791,26 @@ static NOINLINE void send_file_and_exit(const char *url, int what)
}
#endif
#if ENABLE_FEATURE_HTTPD_LAST_MODIFIED
- if (G.if_modified_since) {
- if (DEBUG)
- bb_perror_msg("If-Modified-Since and file's Last-Modified are: '%s' '%s'\n", G.if_modified_since, G.last_mod_date);
- /* Simple match If-Modified-Since and Last-Modified as plain string.
- * In most cases client will send If-Modified-Since exactly the same as it retrieved on previous GET.
- * If a resource wasn't updated then they will be just the same and return 304.
- * If resource was updated then client's If-Modified-Since will be outdated and not the same and return 200.
- * If the If-Modified-Since is a custom date and not from cached resource then this match will always fail and return 200.
- * But such cases normally are not expected. */
- if (strcmp(G.if_modified_since, G.last_mod_date) == 0) {
- send_headers_and_exit(HTTP_NOT_MODIFIED);
+ #if ENABLE_FEATURE_HTTPD_ETAG
+ /* if ETag present but wasn't matched then no sense to match by If-Modified-Since */
+ if (!G.if_none_match) {
+ #endif
+ if (G.if_modified_since) {
+ if (DEBUG)
+ bb_perror_msg("If-Modified-Since and file's Last-Modified are: '%s' '%s'\n", G.if_modified_since, G.last_mod_date);
+ /* Simple match If-Modified-Since and Last-Modified as plain string.
+ * In most cases client will send If-Modified-Since exactly the same as it retrieved on previous GET.
+ * If a resource wasn't updated then they will be just the same and return 304.
+ * If resource was updated then client's If-Modified-Since will be outdated and not the same and return 200.
+ * If the If-Modified-Since is a custom date and not from cached resource then this match will always fail and return 200.
+ * But such cases normally are not expected. */
+ if (strcmp(G.if_modified_since, G.last_mod_date) == 0) {
+ send_headers_and_exit(HTTP_NOT_MODIFIED);
+ }
}
+ #if ENABLE_FEATURE_HTTPD_ETAG
}
+ #endif
#endif
/* If you want to know about EPIPE below
* (happens if you abort downloads from local httpd): */
--
2.27.0
More information about the busybox
mailing list