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

Message ID 20180702125210.9749-1-fe@dev.tdt.de
State New
Delegated to: Jo-Philipp Wich
Headers show
Series
  • [OpenWrt-Devel,1/2] services/uhttpd: add -M option for Last-Modified header sending
Related show

Commit Message

Florian Eckert July 2, 2018, 12:52 p.m.
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@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

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;
+ };
+