[PATCH 0/6] httpd: Match If-Modified-Since and Last-Modified to return 304
Sergey Ponomarev
stokito at gmail.com
Sat Jan 9 21:09:45 UTC 2021
Recently to httpd was added commit 4864a68 "httpd: Support caching via ETag header".
It works simple: in response to GET request we add ETag header built from file's mtime and size.
Client caches the file and on next GET request adds it into If-None-Match header.
Server checks that current file's ETag the same as If-None-Match and responds with 304 Not Modified without payload.
The patch adds similar logic to validate If-Modified-Since against Last-Modified.
This will be useful for 'wget -N' command which sends If-Modified-Since for existing file.
Also the fix can be easily and safely ported to old BB versions.
Here is an example of usage:
WWW_DIR=$(mktemp -d)
echo "<script>document.write(new Date(document.lastModified).toISOString())</script>" > "$WWW_DIR/last-mod.html"
touch -d '2021-01-01 00:00:00 +0000' "$WWW_DIR/last-mod.html"
httpd -vvv -p 8080 -h "$WWW_DIR"
echo 'curl will return 304 Not Modified with ETag: "5fee6600-4f":'
curl -s -I 'http://localhost:8080/last-mod.html' \
--header 'If-None-Match: "5fee6600-4f"' \
--header 'If-Modified-Since: Fri, 01 Jan 2021 00:00:00 GMT'
The two last commits are not related but will be nice to apply.
Sergey Ponomarev (6):
httpd: Last-Modified optimization
httpd: Match If-Modified-Since and Last-Modified to return 304
httpd: Match If-Modified-Since only when If-None-Match is not present
httpd: Add Last-Modified only if resource returned with 200
Fix Content-type header name to Content-Type
httpd_post_upload.cgi: use mktemp to avoid $RANDOM
networking/httpd.c | 121 +++++++++++++++++++++----------
networking/httpd_post_upload.cgi | 2 +-
2 files changed, 85 insertions(+), 38 deletions(-)
--
2.27.0
More information about the busybox
mailing list