web/request.py
branchstable
changeset 8611 51068fe1e39a
parent 8610 b1145ad53999
child 8612 3bb96935a6b9
equal deleted inserted replaced
8610:b1145ad53999 8611:51068fe1e39a
   608             warn('[3.13] remove_cookie now take only a name as argument',
   608             warn('[3.13] remove_cookie now take only a name as argument',
   609                  DeprecationWarning, stacklevel=2)
   609                  DeprecationWarning, stacklevel=2)
   610             name = bwcompat
   610             name = bwcompat
   611         self.set_cookie(name, '', maxage=0, expires=date(2000, 1, 1))
   611         self.set_cookie(name, '', maxage=0, expires=date(2000, 1, 1))
   612 
   612 
   613     def set_content_type(self, content_type, filename=None, encoding=None):
   613     def set_content_type(self, content_type, filename=None, encoding=None,
       
   614                          disposition='attachment'):
   614         """set output content type for this request. An optional filename
   615         """set output content type for this request. An optional filename
   615         may be given
   616         may be given.
       
   617 
       
   618         The disposition argument may be `attachement` or `inline` as specified
       
   619         for the Content-disposition HTTP header. The disposition parameter have
       
   620         no effect if no filename are specified.
   616         """
   621         """
   617         if content_type.startswith('text/') and ';charset=' not in content_type:
   622         if content_type.startswith('text/') and ';charset=' not in content_type:
   618             content_type += ';charset=' + (encoding or self.encoding)
   623             content_type += ';charset=' + (encoding or self.encoding)
   619         self.set_header('content-type', content_type)
   624         self.set_header('content-type', content_type)
   620         if filename:
   625         if filename:
   621             header = ['attachment']
   626             header = [disposition]
   622             unicode_filename = None
   627             unicode_filename = None
   623             try:
   628             try:
   624                 ascii_filename = filename.encode('ascii')
   629                 ascii_filename = filename.encode('ascii')
   625             except UnicodeEncodeError:
   630             except UnicodeEncodeError:
   626                 # fallback filename for very old browser
   631                 # fallback filename for very old browser