Changeset 14:4e69ddcc5e2b
- 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
| r12 |
r14 |
|
| 21 | 21 | # SOFTWARE. |
|---|
| 22 | 22 | |
|---|
| 23 | | - use "random" names for static files used by websourcebrowser itself |
|---|
| 24 | 23 | - handle directories as GET paths |
|---|
| 25 | 24 | - put directory display on the left (or right? configurable?) |
|---|
| r13 |
r14 |
|
| 24 | 24 | import cgi |
|---|
| 25 | 25 | import codecs |
|---|
| | 26 | import email.utils |
|---|
| 26 | 27 | import os |
|---|
| 27 | 28 | import sys |
|---|
| | 29 | import time |
|---|
| 28 | 30 | |
|---|
| 29 | 31 | try: |
|---|
| … | … | |
| 109 | 111 | |
|---|
| 110 | 112 | def _emit_file(self, text, title=u"", content_type="text/html", |
|---|
| 111 | | http_status=HTTP_OK): |
|---|
| | 113 | http_status=HTTP_OK, mtime=None): |
|---|
| 112 | 114 | """ |
|---|
| 113 | 115 | Emit the `text` on the HTTP output stream with a content type |
|---|
| … | … | |
| 122 | 124 | header_content_type = content_type |
|---|
| 123 | 125 | self.send_header("Content-type", header_content_type) |
|---|
| | 126 | if mtime: |
|---|
| | 127 | self.send_header("Last-Modified", email.utils.formatdate(mtime)) |
|---|
| 124 | 128 | self.end_headers() |
|---|
| 125 | 129 | if content_type == "text/html": |
|---|
| … | … | |
| 137 | 141 | if self.path == ("/" + STATIC_PREFIX + CSS_FILE_NAME): |
|---|
| 138 | 142 | 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())) |
|---|
| 140 | 145 | return |
|---|
| 141 | 146 | path = self.path[1:] |
|---|
| … | … | |
| 154 | 159 | # assume title is UTF-8-encoded though we don't know for sure |
|---|
| 155 | 160 | 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)) |
|---|
| 157 | 162 | |
|---|
| 158 | 163 | |
|---|