[Twisted-web] [PATCH] add content-type to error responses

Wilfredo Sánchez Vega wsanchez at wsanchez.net
Mon Jul 11 16:24:04 MDT 2005


   Errors handled by error.defaultErrorHandler() do not set the  
content-type header.  This patch sets that header in the code that  
emits the HTML.

     -wsv


Index: error.py
===================================================================
--- error.py    (revision 14132)
+++ error.py    (working copy)
@@ -5,7 +5,7 @@
Default error output filter for twisted.web2.
"""
-from twisted.web2 import stream
+from twisted.web2 import stream, http_headers
from twisted.web2.responsecode import *
# 300 - Should include entity with choices
@@ -91,7 +91,10 @@
      body = ("<html><head><title>%d %s</title></head>"
              "<body><h1>%s</h1>%s</body></html>") % (
          response.code, title, title, message)
+
      response.stream = stream.MemoryStream(body)
+    response.headers.setHeader("content-type", http_headers.MimeType 
('text', 'html'))
+
      return response
defaultErrorHandler.handleErrors = True
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3057 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-web/attachments/20050711/29f7f89d/smime.bin


More information about the Twisted-web mailing list