Changeset 14:4e69ddcc5e2b

Show
Ignore:
Timestamp:
2007-06-23 18:41:26 (1 year ago)
Author:
Stefan Schwarzer <sschwarzer@sschwarzer.net>
branch:
default
Message:
Include Last-Modified header for files.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • todo.txt

    r12 r14  
    2121# SOFTWARE. 
    2222 
    23 - use "random" names for static files used by websourcebrowser itself 
    2423- handle directories as GET paths 
    2524- put directory display on the left (or right? configurable?) 
  • websourcebrowser.py

    r13 r14  
    2424import cgi 
    2525import codecs 
     26import email.utils 
    2627import os 
    2728import sys 
     29import time 
    2830 
    2931try: 
     
    109111 
    110112    def _emit_file(self, text, title=u"", content_type="text/html", 
    111                    http_status=HTTP_OK): 
     113                   http_status=HTTP_OK, mtime=None): 
    112114        """ 
    113115        Emit the `text` on the HTTP output stream with a content type 
     
    122124            header_content_type = content_type 
    123125        self.send_header("Content-type", header_content_type) 
     126        if mtime: 
     127            self.send_header("Last-Modified", email.utils.formatdate(mtime)) 
    124128        self.end_headers() 
    125129        if content_type == "text/html": 
     
    137141        if self.path == ("/" + STATIC_PREFIX + CSS_FILE_NAME): 
    138142            self._emit_file(self._get_file(actual_css_path()), 
    139                             content_type="text/css") 
     143                            content_type="text/css", 
     144                            mtime=os.path.getmtime(actual_css_path())) 
    140145            return 
    141146        path = self.path[1:] 
     
    154159            # assume title is UTF-8-encoded though we don't know for sure 
    155160            title = relative_path.decode("UTF-8") 
    156             self._emit_file(html, title=title
     161            self._emit_file(html, title=title, mtime=os.path.getmtime(path)
    157162 
    158163