1.1 --- a/MoinSupport.py Tue Jul 17 00:42:10 2012 +0200
1.2 +++ b/MoinSupport.py Sat Aug 18 20:33:04 2012 +0200
1.3 @@ -10,7 +10,7 @@
1.4
1.5 from DateSupport import *
1.6 from MoinMoin.Page import Page
1.7 -from MoinMoin import wikiutil
1.8 +from MoinMoin import config, wikiutil
1.9 from StringIO import StringIO
1.10 from shlex import shlex
1.11 import re
1.12 @@ -241,6 +241,32 @@
1.13 else:
1.14 return request.env.get((prefix and prefix + "_" or "") + header_name.upper())
1.15
1.16 +def writeHeaders(request, mimetype, metadata, status=None):
1.17 +
1.18 + """
1.19 + Using the 'request', write resource headers using the given 'mimetype',
1.20 + based on the given 'metadata'. If the optional 'status' is specified, set
1.21 + the status header to the given value.
1.22 + """
1.23 +
1.24 + send_headers = get_send_headers(request)
1.25 +
1.26 + # Define headers.
1.27 +
1.28 + headers = ["Content-Type: %s; charset=%s" % (mimetype, config.charset)]
1.29 +
1.30 + # Define the last modified time.
1.31 + # NOTE: Consider using request.httpDate.
1.32 +
1.33 + latest_timestamp = metadata.get("last-modified")
1.34 + if latest_timestamp:
1.35 + headers.append("Last-Modified: %s" % latest_timestamp.as_HTTP_datetime_string())
1.36 +
1.37 + if status:
1.38 + headers.append("Status: %s" % status)
1.39 +
1.40 + send_headers(headers)
1.41 +
1.42 # Content/media type and preferences support.
1.43
1.44 class MediaRange: