summaryrefslogtreecommitdiff
path: root/paste/fileapp.py
diff options
context:
space:
mode:
authorianb <devnull@localhost>2007-02-18 23:44:15 +0000
committerianb <devnull@localhost>2007-02-18 23:44:15 +0000
commit1cf4f03c6a0347ea8bf64b8b6e1f7c72572a33c8 (patch)
tree7a4d8d36eaa542dc20ecee958e5628bc22528b9a /paste/fileapp.py
parent73d64e41b489e8229bddc47bf40e7630797a2acc (diff)
downloadpaste-1cf4f03c6a0347ea8bf64b8b6e1f7c72572a33c8.tar.gz
Prefer ETags over Last-Modified when calculating 304s
Diffstat (limited to 'paste/fileapp.py')
-rw-r--r--paste/fileapp.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/paste/fileapp.py b/paste/fileapp.py
index 1180c0f..dce8780 100644
--- a/paste/fileapp.py
+++ b/paste/fileapp.py
@@ -97,25 +97,17 @@ class DataApp(object):
return exc(environ, start_response)
return self.get(environ, start_response)
+ def calculate_etag(self):
+ return str(self.last_modified) + '-' + str(self.content_length)
+
def get(self, environ, start_response):
headers = self.headers[:]
- current_etag = str(self.last_modified)
+ current_etag = self.calculate_etag()
ETAG.update(headers, current_etag)
if self.expires is not None:
EXPIRES.update(headers, delta=self.expires)
try:
- client_clock = IF_MODIFIED_SINCE.parse(environ)
- if client_clock >= int(self.last_modified):
- # horribly inefficient, n^2 performance, yuck!
- for head in list_headers(entity=True):
- head.delete(headers)
- start_response('304 Not Modified', headers)
- return [''] # empty body
- except HTTPBadRequest, exce:
- return exce.wsgi_application(environ, start_response)
-
- try:
client_etags = IF_NONE_MATCH.parse(environ)
if client_etags:
for etag in client_etags:
@@ -128,6 +120,22 @@ class DataApp(object):
except HTTPBadRequest, exce:
return exce.wsgi_application(environ, start_response)
+ # If we get If-None-Match and If-Modified-Since, and
+ # If-None-Match doesn't match, then we should not try to
+ # figure out If-Modified-Since (which has 1-second granularity
+ # and just isn't as accurate)
+ if not client_etags:
+ try:
+ client_clock = IF_MODIFIED_SINCE.parse(environ)
+ if client_clock >= int(self.last_modified):
+ # horribly inefficient, n^2 performance, yuck!
+ for head in list_headers(entity=True):
+ head.delete(headers)
+ start_response('304 Not Modified', headers)
+ return [''] # empty body
+ except HTTPBadRequest, exce:
+ return exce.wsgi_application(environ, start_response)
+
(lower, upper) = (0, self.content_length - 1)
range = RANGE.parse(environ)
if range and 'bytes' == range[0] and 1 == len(range[1]):