From c6e565fd33e0d917133a129bc2a578aebac4c43b Mon Sep 17 00:00:00 2001
From: hniksic <devnull@localhost>
Date: Thu, 26 Apr 2001 22:26:44 -0700
Subject: [PATCH] [svn] Send the no-cache directive when required regardless of
 whether we're going through a proxy. Published in
 <sxsitjqncbx.fsf@florida.arsdigita.de>.

---
 src/ChangeLog |  9 +++++++++
 src/http.c    | 12 ++++++++++--
 src/init.c    |  4 ++--
 src/options.h |  2 +-
 4 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index cadb7bb1..19e9cb2f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
+2001-04-27  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+	* http.c (http_loop): If allow_cache is zero, always disable
+	caching, not only when retrieving through proxy.
+
+	* init.c: Ditto.
+
+	* options.h (struct options): Rename proxy_cache to allow_cache.
+
 2001-04-27  Hrvoje Niksic  <hniksic@arsdigita.com>
 
 	* http.c (mktime_from_utc): Improve documentation.
diff --git a/src/http.c b/src/http.c
index 34f97ce7..ecf29384 100644
--- a/src/http.c
+++ b/src/http.c
@@ -1521,8 +1521,16 @@ File `%s' already there, will not retrieve.\n"), u->local);
 	  && file_exists_p (locf))
 	if (stat (locf, &st) == 0 && S_ISREG (st.st_mode))
 	  hstat.restval = st.st_size;
-      /* Decide whether to send the no-cache directive.  */
-      if (u->proxy && (count > 1 || (opt.proxy_cache == 0)))
+
+      /* Decide whether to send the no-cache directive.  We send it in
+	 two cases:
+	   a) we're using a proxy, and we're past our first retrieval.
+	      Some proxies are notorious for caching incomplete data, so
+	      we require a fresh get.
+	   b) caching is explicitly inhibited. */
+      if ((u->proxy && count > 1) /* a */
+	  || !opt.allow_cache	  /* b */
+	  )
 	*dt |= SEND_NOCACHE;
       else
 	*dt &= ~SEND_NOCACHE;
diff --git a/src/init.c b/src/init.c
index 46fd6b91..d824d8c3 100644
--- a/src/init.c
+++ b/src/init.c
@@ -104,7 +104,7 @@ static struct {
   { "backups",		&opt.backups,		cmd_number },
   { "base",		&opt.base_href,		cmd_string },
   { "bindaddress",	&opt.bind_address,	cmd_address },
-  { "cache",		&opt.proxy_cache,	cmd_boolean },
+  { "cache",		&opt.allow_cache,	cmd_boolean },
   { "continue",		&opt.always_rest,	cmd_boolean },
   { "convertlinks",	&opt.convert_links,	cmd_boolean },
   { "cookies",		&opt.cookies,		cmd_boolean },
@@ -237,7 +237,7 @@ defaults (void)
   tmp = getenv ("no_proxy");
   if (tmp)
     opt.no_proxy = sepstring (tmp);
-  opt.proxy_cache = 1;
+  opt.allow_cache = 1;
 
 #ifdef HAVE_SELECT
   opt.timeout = 900;
diff --git a/src/options.h b/src/options.h
index 90b5919e..42bfd7c6 100644
--- a/src/options.h
+++ b/src/options.h
@@ -92,7 +92,7 @@ struct options
   int http_keep_alive;		/* whether we use keep-alive */
 
   int use_proxy;		/* Do we use proxy? */
-  int proxy_cache;		/* Do we load from proxy cache? */
+  int allow_cache;		/* Do we allow server-side caching? */
   char *http_proxy, *ftp_proxy, *https_proxy;
   char **no_proxy;
   char *base_href;