Mercurial > moin > 1.9
changeset 5591:1dff6cfdcf90
http headers: for most cases, do not use .add, but .__setitem__
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Sat, 27 Feb 2010 02:04:17 +0100 |
parents | 60f0768f0bcf |
children | f4f63ac82b81 |
files | MoinMoin/Page.py MoinMoin/action/AttachFile.py MoinMoin/action/PackagePages.py MoinMoin/action/backup.py MoinMoin/action/cache.py MoinMoin/action/rss_rc.py MoinMoin/action/sisterpages.py MoinMoin/web/contexts.py MoinMoin/wsgiapp.py |
diffstat | 9 files changed, 29 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/MoinMoin/Page.py Fri Feb 26 10:32:03 2010 +0100 +++ b/MoinMoin/Page.py Sat Feb 27 02:04:17 2010 +0100 @@ -977,13 +977,13 @@ request.status_code = 200 request.last_modified = os.path.getmtime(self._text_filename()) text = self.encodeTextMimeType(self.body) - #request.setHttpHeader("Content-Length: %d" % len(text)) # XXX WRONG! text is unicode obj, but we send utf-8! + #request.headers['Content-Length'] = len(text) # XXX WRONG! text is unicode obj, but we send utf-8! if content_disposition: # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs # There is no solution that is compatible to IE except stripping non-ascii chars filename_enc = "%s.txt" % self.page_name.encode(config.charset) dispo_string = '%s; filename="%s"' % (content_disposition, filename_enc) - request.headers.add('Content-Disposition', dispo_string) + request.headers['Content-Disposition'] = dispo_string else: request.status_code = 404 text = u"Page %s not found." % self.page_name @@ -1097,7 +1097,7 @@ # if it does, we must not use the page file mtime as last modified value # The following code is commented because it is incorrect for dynamic pages: #lastmod = os.path.getmtime(self._text_filename()) - #request.setHttpHeader("Last-Modified: %s" % util.timefuncs.formathttpdate(lastmod)) + #request.headers['Last-Modified'] = util.timefuncs.formathttpdate(lastmod) pass else: request.status_code = 404
--- a/MoinMoin/action/AttachFile.py Fri Feb 26 10:32:03 2010 +0100 +++ b/MoinMoin/action/AttachFile.py Sat Feb 27 02:04:17 2010 +0100 @@ -818,13 +818,13 @@ content_dispo = dangerous and 'attachment' or 'inline' now = time.time() - request.headers.add('Date', http_date(now)) - request.headers.add('Content-Type', content_type) - request.headers.add('Last-Modified', http_date(timestamp)) - request.headers.add('Expires', http_date(now - 365 * 24 * 3600)) - #request.headers.add('Content-Length', os.path.getsize(fpath)) + request.headers['Date'] = http_date(now) + request.headers['Content-Type'] = content_type + request.headers['Last-Modified'] = http_date(timestamp) + request.headers['Expires'] = http_date(now - 365 * 24 * 3600) + #request.headers['Content-Length'] = os.path.getsize(fpath) content_dispo_string = '%s; filename="%s"' % (content_dispo, filename_enc) - request.headers.add('Content-Disposition', content_dispo_string) + request.headers['Content-Disposition'] = content_dispo_string # send data request.send_file(ci.get(filename)) @@ -859,13 +859,13 @@ content_dispo = dangerous and 'attachment' or 'inline' now = time.time() - request.headers.add('Date', http_date(now)) - request.headers.add('Content-Type', content_type) - request.headers.add('Last-Modified', http_date(timestamp)) - request.headers.add('Expires', http_date(now - 365 * 24 * 3600)) - request.headers.add('Content-Length', os.path.getsize(fpath)) + request.headers['Date'] = http_date(now) + request.headers['Content-Type'] = content_type + request.headers['Last-Modified'] = http_date(timestamp) + request.headers['Expires'] = http_date(now - 365 * 24 * 3600) + request.headers['Content-Length'] = os.path.getsize(fpath) content_dispo_string = '%s; filename="%s"' % (content_dispo, filename_enc) - request.headers.add('Content-Disposition', content_dispo_string) + request.headers['Content-Disposition'] = content_dispo_string # send data request.send_file(open(fpath, 'rb'))
--- a/MoinMoin/action/PackagePages.py Fri Feb 26 10:32:03 2010 +0100 +++ b/MoinMoin/action/PackagePages.py Sat Feb 27 02:04:17 2010 +0100 @@ -82,9 +82,9 @@ request = self.request filelike = cStringIO.StringIO() package = self.collectpackage(unpackLine(pagelist, ","), filelike, target, include_attachments) - request.content_type = 'application/zip' - request.content_length = filelike.tell() - request.headers.add('Content-Disposition', 'inline; filename="%s"' % target) + request.headers['Content-Type'] = 'application/zip' + request.headers['Content-Length'] = filelike.tell() + request.headers['Content-Disposition'] = 'inline; filename="%s"' % target request.write(filelike.getvalue()) filelike.close()
--- a/MoinMoin/action/backup.py Fri Feb 26 10:32:03 2010 +0100 +++ b/MoinMoin/action/backup.py Sat Feb 27 02:04:17 2010 +0100 @@ -37,8 +37,8 @@ """ Send compressed tar file """ dateStamp = time.strftime("%Y-%m-%d--%H-%M-%S-UTC", time.gmtime()) filename = "%s-%s.tar.%s" % (request.cfg.siteid, dateStamp, request.cfg.backup_compression) - request.content_type = 'application/octet-stream' - request.headers.add('Content-Disposition', 'inline; filename="%s"' % filename) + request.headers['Content-Type'] = 'application/octet-stream' + request.headers['Content-Disposition'] = 'inline; filename="%s"' % filename tar = tarfile.open(fileobj=request, mode="w|%s" % request.cfg.backup_compression) # allow GNU tar's longer file/pathnames tar.posix = False
--- a/MoinMoin/action/cache.py Fri Feb 26 10:32:03 2010 +0100 +++ b/MoinMoin/action/cache.py Sat Feb 27 02:04:17 2010 +0100 @@ -219,17 +219,9 @@ if request.if_modified_since == last_modified: request.status_code = 304 else: + for k, v in headers: + request.headers.add(k, v) data_file = _get_datafile(request, key) - for key, value in headers: - lkey = key.lower() - if lkey == 'content-type': - request.content_type = value - elif lkey == 'last-modified': - request.last_modified = value - elif lkey == 'content-length': - request.content_length = value - else: - request.headers.add(key, value) request.send_file(data_file) except caching.CacheError: request.status_code = 404
--- a/MoinMoin/action/rss_rc.py Fri Feb 26 10:32:03 2010 +0100 +++ b/MoinMoin/action/rss_rc.py Sat Feb 27 02:04:17 2010 +0100 @@ -102,7 +102,7 @@ request.mime_type = 'text/xml' request.expires = expires request.last_modified = lastmod - request.headers.add('Etag', etag) + request.headers['Etag'] = etag # send the generated XML document baseurl = request.url_root
--- a/MoinMoin/action/sisterpages.py Fri Feb 26 10:32:03 2010 +0100 +++ b/MoinMoin/action/sisterpages.py Sat Feb 27 02:04:17 2010 +0100 @@ -48,7 +48,7 @@ request.mime_type = 'text/plain' request.expires = expires request.last_modified = timestamp - request.headers.add("Etag", etag) + request.headers['Etag'] = etag # send the generated XML document # Get list of user readable pages
--- a/MoinMoin/web/contexts.py Fri Feb 26 10:32:03 2010 +0100 +++ b/MoinMoin/web/contexts.py Sat Feb 27 02:04:17 2010 +0100 @@ -239,6 +239,7 @@ raise status[resultcode](msg) def setHttpHeader(self, header): + logging.warning("Deprecated call to request.setHttpHeader('k:v'), use request.headers.add/set('k', 'v')") header, value = header.split(':', 1) self.headers.add(header, value) @@ -260,10 +261,10 @@ return if level == 1: - self.headers.set('Cache-Control', 'private, must-revalidate, max-age=10') + self.headers['Cache-Control'] = 'private, must-revalidate, max-age=10' elif level == 2: - self.headers.set('Cache-Control', 'no-cache') - self.headers.set('Pragma', 'no-cache') + self.headers['Cache-Control'] = 'no-cache' + self.headers['Pragma'] = 'no-cache' self.request.expires = time.time() - 3600 * 24 * 365 def http_redirect(self, url, code=302):
--- a/MoinMoin/wsgiapp.py Fri Feb 26 10:32:03 2010 +0100 +++ b/MoinMoin/wsgiapp.py Sat Feb 27 02:04:17 2010 +0100 @@ -125,7 +125,7 @@ hs = HeaderSet(('Cookie', 'User-Agent')) if not cfg.language_ignore_browser: hs.add('Accept-Language') - request.headers.add('Vary', str(hs)) + request.headers['Vary'] = str(hs) # Handle request. We have these options: # 1. jump to page where user left off