1.1 --- a/WebStack/Resources/Static.py Sun Aug 24 20:51:10 2008 +0200
1.2 +++ b/WebStack/Resources/Static.py Sat Nov 15 02:33:06 2008 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Resources for serving static content.
1.6
1.7 -Copyright (C) 2004, 2005, 2006 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2004, 2005, 2006, 2007, 2008 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This library is free software; you can redistribute it and/or
1.11 modify it under the terms of the GNU Lesser General Public
1.12 @@ -22,6 +22,7 @@
1.13
1.14 from WebStack.Generic import ContentType, EndOfResponse
1.15 import os
1.16 +import email.utils
1.17
1.18 class DirectoryResource:
1.19
1.20 @@ -117,7 +118,11 @@
1.21
1.22 # Write the file to the client.
1.23
1.24 - f = open(os.path.join(self.directory, filename), "rb")
1.25 + pathname = os.path.join(self.directory, filename)
1.26 + mtime = email.utils.formatdate(os.path.getmtime(pathname), usegmt=1)
1.27 + trans.set_header_value("Last-Modified", mtime)
1.28 +
1.29 + f = open(pathname, "rb")
1.30 out.write(f.read())
1.31 f.close()
1.32
1.33 @@ -143,7 +148,10 @@
1.34 self.content_type = content_type
1.35
1.36 def respond(self, trans):
1.37 + mtime = email.utils.formatdate(os.path.getmtime(self.filename), usegmt=1)
1.38 +
1.39 trans.set_content_type(self.content_type)
1.40 + trans.set_header_value("Last-Modified", mtime)
1.41 f = open(self.filename, "rb")
1.42 trans.get_response_stream().write(f.read())
1.43 f.close()