Skip to content
Browse files

Tweak cachability when reading from the disk cache.

This should solve the problem of uncachable objects becoming cachable
again after they are read from the disk cache.  Reported by J. P. Larocque.

darcs-hash:20061218144256-4cc09-15ee7febcf7a4849fd4354069db15ffcadebb7bf.gz
  • Loading branch information...
1 parent 8519b50 commit 148f04ffb2a867b5930d90cd835664bf6c59873f @jech committed
Showing with 44 additions and 33 deletions.
  1. +2 −0 diskcache.c
  2. +39 −0 http.c
  3. +1 −0 http.h
  4. +1 −32 server.c
  5. +1 −1 server.h
View
2 diskcache.c
@@ -1050,6 +1050,8 @@ validateEntry(ObjectPtr object, int fd,
}
}
+ httpTweakCachability(object);
+
if(buf_is_chunk)
dispose_chunk(buf);
else
View
39 http.c
@@ -992,3 +992,42 @@ urlDecode(char *buf, int n)
destroyAtomList(list);
return NULL;
}
+
+void
+httpTweakCachability(ObjectPtr object)
+{
+ int code = object->code;
+
+ if((object->cache_control & CACHE_AUTHORIZATION) &&
+ !(object->cache_control & CACHE_PUBLIC))
+ object->cache_control |= (CACHE_NO_HIDDEN | OBJECT_LINEAR);
+
+ /* This is not required by RFC 2616 -- but see RFC 3143 2.1.1. We
+ manically avoid caching replies that we don't know how to
+ handle, even if Expires or Cache-Control says otherwise. As to
+ known uncacheable replies, we obey Cache-Control and default to
+ allowing sharing but not caching. */
+ if(code != 200 && code != 206 &&
+ code != 300 && code != 301 && code != 302 && code != 303 &&
+ code != 304 && code != 307 &&
+ code != 403 && code != 404 && code != 405 && code != 416) {
+ object->cache_control |= (CACHE_NO_HIDDEN | OBJECT_LINEAR);
+ } else if(code != 200 && code != 206 &&
+ code != 300 && code != 301 && code != 304 &&
+ code != 410) {
+ if(object->expires < 0 && !(object->cache_control & CACHE_PUBLIC)) {
+ object->cache_control |= CACHE_NO_HIDDEN;
+ }
+ } else if(dontCacheRedirects && (code == 301 || code == 302)) {
+ object->cache_control |= CACHE_NO_HIDDEN;
+ }
+
+ if(urlIsUncachable(object->key, object->key_size)) {
+ object->cache_control |= CACHE_NO_HIDDEN;
+ }
+
+ if((object->cache_control & CACHE_NO_STORE) ||
+ ((object->cache_control & CACHE_VARY) &&
+ (!object->etag || dontTrustVaryETag)))
+ object->cache_control |= CACHE_NO_HIDDEN;
+}
View
1 http.h
@@ -169,3 +169,4 @@ int httpWriteErrorHeaders(char *buf, int size, int offset, int do_body,
int code, AtomPtr message, int close, AtomPtr,
char *url, int url_len, char *etag);
AtomListPtr urlDecode(char*, int);
+void httpTweakCachability();
View
33 server.c
@@ -2164,33 +2164,7 @@ httpServerHandlerHeaders(int eof,
break;
}
- if((cache_control.flags & CACHE_AUTHORIZATION) &&
- !(cache_control.flags & CACHE_PUBLIC))
- new_object->cache_control |= (CACHE_NO_HIDDEN | OBJECT_LINEAR);
-
- /* This is not required by RFC 2616 -- but see RFC 3143 2.1.1. We
- manically avoid caching replies that we don't know how to
- handle, even if Expires or Cache-Control says otherwise. As to
- known uncacheable replies, we obey Cache-Control and default to
- allowing sharing but not caching. */
- if(code != 200 && code != 206 &&
- code != 300 && code != 301 && code != 302 && code != 303 &&
- code != 304 && code != 307 &&
- code != 403 && code != 404 && code != 405 && code != 416) {
- new_object->cache_control |= (CACHE_NO_HIDDEN | OBJECT_LINEAR);
- } else if(code != 200 && code != 206 &&
- code != 300 && code != 301 && code != 304 &&
- code != 410) {
- if(new_object->expires < 0 && !(cache_control.flags & CACHE_PUBLIC)) {
- new_object->cache_control |= CACHE_NO_HIDDEN;
- }
- } else if(dontCacheRedirects && (code == 301 || code == 302)) {
- new_object->cache_control |= CACHE_NO_HIDDEN;
- }
-
- if(urlIsUncachable(new_object->key, new_object->key_size)) {
- new_object->cache_control |= CACHE_NO_HIDDEN;
- }
+ httpTweakCachability(new_object);
if(!via)
new_via = internAtomF("%s %s",
@@ -2207,11 +2181,6 @@ httpServerHandlerHeaders(int eof,
new_object->via = new_via;
}
- if((new_object->cache_control & CACHE_NO_STORE) ||
- ((new_object->cache_control & CACHE_VARY) &&
- (!new_object->etag || dontTrustVaryETag)))
- new_object->cache_control |= CACHE_NO_HIDDEN;
-
if(new_object->flags & OBJECT_INITIAL) {
objectPartial(new_object, full_len, headers);
} else {
View
2 server.h
@@ -20,7 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-extern int serverExpireTime;
+extern int serverExpireTime, dontCacheRedirects, dontTrustVaryETag;
typedef struct _HTTPServer {
char *name;

0 comments on commit 148f04f

Please sign in to comment.
Something went wrong with that request. Please try again.