[OpenWrt-Devel] [PATCH 1/2] services/uhttpd: add -M option for Last-Modified header sending

Florian Eckert fe at dev.tdt.de
Mon Jul 2 08:52:09 EDT 2018


If uhttpd is started with the option -M then Last-Modified header is not
send during ok respond. We have already an ETag header set which is more
accurate.

See URL:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Etag

So make sending of Last-Modified header optional with a config option.
If the option is not set then the behaviour is as before this option was
added.

Signed-off-by: Florian Eckert <fe at dev.tdt.de>
---
 ...ct-if-last-modified-header-should-be-send.patch | 46 ++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 package/network/services/uhttpd/patches/0001-add-a-M-option-to-select-if-last-modified-header-should-be-send.patch

diff --git a/package/network/services/uhttpd/patches/0001-add-a-M-option-to-select-if-last-modified-header-should-be-send.patch b/package/network/services/uhttpd/patches/0001-add-a-M-option-to-select-if-last-modified-header-should-be-send.patch
new file mode 100644
index 0000000000..9835ca8cfd
--- /dev/null
+++ b/package/network/services/uhttpd/patches/0001-add-a-M-option-to-select-if-last-modified-header-should-be-send.patch
@@ -0,0 +1,46 @@
+--- a/file.c
++++ b/file.c
+@@ -337,8 +337,9 @@ static void uh_file_response_ok_hdrs(str
+ 
+ 	if (s) {
+ 		ustream_printf(cl->us, "ETag: %s\r\n", uh_file_mktag(s, buf, sizeof(buf)));
+-		ustream_printf(cl->us, "Last-Modified: %s\r\n",
+-			       uh_file_unix2date(s->st_mtime, buf, sizeof(buf)));
++		if(!conf.no_last_modified_header)
++			ustream_printf(cl->us, "Last-Modified: %s\r\n",
++				       uh_file_unix2date(s->st_mtime, buf, sizeof(buf)));
+ 	}
+ 	ustream_printf(cl->us, "Date: %s\r\n",
+ 		       uh_file_unix2date(time(NULL), buf, sizeof(buf)));
+--- a/main.c
++++ b/main.c
+@@ -232,7 +232,7 @@ int main(int argc, char **argv)
+ 	init_defaults_pre();
+ 	signal(SIGPIPE, SIG_IGN);
+ 
+-	while ((ch = getopt(argc, argv, "A:aC:c:Dd:E:fh:H:I:i:K:k:L:l:m:N:n:p:qRr:Ss:T:t:U:u:Xx:y:")) != -1) {
++	while ((ch = getopt(argc, argv, "A:aC:c:Dd:E:fh:H:I:i:K:k:L:l:Mm:N:n:p:qRr:Ss:T:t:U:u:Xx:y:")) != -1) {
+ 		switch(ch) {
+ #ifdef HAVE_TLS
+ 		case 'C':
+@@ -311,6 +311,10 @@ int main(int argc, char **argv)
+ 			conf.rfc1918_filter = 1;
+ 			break;
+ 
++		case 'M':
++			conf.no_last_modified_header = 1;
++			break;
++
+ 		case 'n':
+ 			conf.max_script_requests = atoi(optarg);
+ 			break;
+--- a/uhttpd.h
++++ b/uhttpd.h
+@@ -77,6 +77,7 @@ struct config {
+ 	int ubus_noauth;
+ 	int ubus_cors;
+ 	int cgi_prefix_len;
++	int no_last_modified_header;
+ 	struct list_head cgi_alias;
+ };
+ 
-- 
2.11.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list