[web] allow configuration of the Content-disposition value stable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Tue, 11 Dec 2012 16:57:18 +0100
branchstable
changeset 8611 51068fe1e39a
parent 8610 b1145ad53999
child 8612 3bb96935a6b9
[web] allow configuration of the Content-disposition value The `set_content_type` function now takes and optional `disposition` parameter to control the value of this HTTP header. Use of `Content-disposition: inline` with a filename parameter are valid, so the presence of filename does not allows to choose between `attachment` and `inline`
web/request.py
--- a/web/request.py	Tue Dec 11 17:17:40 2012 +0100
+++ b/web/request.py	Tue Dec 11 16:57:18 2012 +0100
@@ -610,15 +610,20 @@
             name = bwcompat
         self.set_cookie(name, '', maxage=0, expires=date(2000, 1, 1))
 
-    def set_content_type(self, content_type, filename=None, encoding=None):
+    def set_content_type(self, content_type, filename=None, encoding=None,
+                         disposition='attachment'):
         """set output content type for this request. An optional filename
-        may be given
+        may be given.
+
+        The disposition argument may be `attachement` or `inline` as specified
+        for the Content-disposition HTTP header. The disposition parameter have
+        no effect if no filename are specified.
         """
         if content_type.startswith('text/') and ';charset=' not in content_type:
             content_type += ';charset=' + (encoding or self.encoding)
         self.set_header('content-type', content_type)
         if filename:
-            header = ['attachment']
+            header = [disposition]
             unicode_filename = None
             try:
                 ascii_filename = filename.encode('ascii')