[PATCH] httpd: compile-time option to request that browsers never cache content

Joshua Judson Rosen jrosen at harvestai.com
Thu Oct 2 20:28:50 UTC 2014


Mark all served documents as "Cache-control: no-cache".

This can be useful for embedded applications where caching is
very unlikely to be beneficial and very likely to result
in confused users, e.g.: private network; single, local client;
infrequent client->server visits; small pages....

Signed-off-by: Joshua Judson Rosen <jrosen at harvestai.com>
---
 networking/Config.src |   11 +++++++++++
 networking/httpd.c    |    5 +++++
 2 files changed, 16 insertions(+)

diff --git a/networking/Config.src b/networking/Config.src
index e566469..31ff982 100644
--- a/networking/Config.src
+++ b/networking/Config.src
@@ -181,6 +181,17 @@ config FEATURE_HTTPD_RANGES
 	  "Range: bytes=NNN-[MMM]" header. Allows for resuming interrupted
 	  downloads, seeking in multimedia players etc.
 
+config FEATURE_HTTPD_NOCACHE
+	bool "Cache-control: no-cache"
+	default n
+	help
+	  Makes httpd mark all served documents as "Cache-control: no-cache".
+	  This can be useful for embedded applications where caching is
+	  very unlikely to be beneficial and very likely to result
+	  in confused users, e.g.: private network; single, local client;
+	  infrequent client->erver visits; small pages; almost all
+	  pages actually CGI scripts....
+
 config FEATURE_HTTPD_USE_SENDFILE
 	bool "Use sendfile system call"
 	default y
diff --git a/networking/httpd.c b/networking/httpd.c
index 621d9cd..bbccf30 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1007,6 +1007,11 @@ static void send_headers(int responseNum)
 				content_gzip ? "Transfer-length:" : "Content-length:",
 				file_size
 		);
+ 
+#if ENABLE_FEATURE_HTTPD_NOCACHE
+		len += sprintf(iobuf + len,
+			"Cache-control: no-cache\r\n");
+#endif
 	}
 
 	if (content_gzip)
-- 
1.7.10.4



More information about the busybox mailing list