Skip to content
Browse files

Added basic Last-Modified/If-Modified-Since support. It only checks i…

…f the dates are identical, not if the resource has a later date.
  • Loading branch information...
1 parent 3508c2e commit e740369dceb3a77400f9467eb3c1f1345d91f343 @curiousdannii curiousdannii committed Jan 25, 2010
Showing with 27 additions and 4 deletions.
  1. +2 −1 .gitignore
  2. +6 −1 dryapp/drydrop/app/meta/server.py
  3. +19 −2 dryapp/drydrop_handler.py
View
3 .gitignore
@@ -15,4 +15,5 @@ tmtags
.pdbrc
Thumbs.db
_layouts
-shared
+shared
+*~
View
7 dryapp/drydrop/app/meta/server.py
@@ -691,13 +691,18 @@ def Dispatch(self,
c = c + 1
new_path = part.replace(SPACE_MARKER, ' ')
full_path = self._path_adjuster.AdjustPath(new_path)
- status, data = self._read_data_file(full_path, self._vfs)
+ status, data, created_on = self._read_data_file(full_path, self._vfs)
if status==httplib.OK or c==len(parts):
content_type = self._static_file_config_matcher.GetMimeType(new_path)
expiration = self._static_file_config_matcher.GetExpiration(new_path)
outfile.write('Status: %d\r\n' % status)
outfile.write('Content-Type: %s\r\n' % content_type)
+
+ # Send a Last-Modified header
+ HTTP_date = created_on.strftime('%a, %d %b %Y %H:%M:%S GMT')
+ outfile.write('Last-Modified: %s\r\n' % HTTP_date)
+
if expiration:
outfile.write('Expires: %s\r\n'
% email.Utils.formatdate(time.time() + expiration,
View
21 dryapp/drydrop_handler.py
@@ -83,7 +83,9 @@ def ReadDataFile(path, vfs):
if resource.content is None:
logging.warning('Missing file "%s"', path)
return httplib.NOT_FOUND, ""
- return httplib.OK, resource.content
+
+ # Return the content and timestamp
+ return httplib.OK, resource.content, resource.created_on
class AppHandler(webapp.RequestHandler):
@@ -111,6 +113,8 @@ def meta_dispatch(self, root, config_source, request_path, request_headers, requ
from drydrop.app.meta.server import ParseAppConfig, MatcherDispatcher, RewriteResponse, cStringIO
import string
import logging
+
+ HTTP_date = ''
logging.debug("Meta: dispatching %s", request_path)
@@ -141,7 +145,20 @@ def meta_dispatch(self, root, config_source, request_path, request_headers, requ
del self.response.headers[k]
for h in header_list:
parts = h.split(':')
- self.response.headers.add_header(parts.pop(0), string.join(parts, ':'))
+ header_name = parts.pop(0)
+ header_value = string.join(parts, ':')
+ self.response.headers.add_header(header_name, header_value)
+
+ # Save the Last-Modified header
+ if header_name == 'Last-Modified':
+ HTTP_date = header_value
+
+ # Use the If-Modified-Since header...
+ if 'If-Modified-Since' in request_headers:
+ if request_headers['If-Modified-Since'].lower().strip() == HTTP_date.lower().strip():
+ # Return 304 (Not Modified)
+ self.response.set_status(304, 'Not Modified')
+ return True
# If the request doesn't have an extension, return text/html
basename, extension = os.path.splitext(request_path)

0 comments on commit e740369

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