HTTPResponse.handleException should set the content type

Bug #98413 reported by Marius Gedminas
2
Affects Status Importance Assigned to Milestone
Zope 3
Status tracked in 3.4
3.4
Fix Released
Critical
Dmitry Vasiliev

Bug Description

zope.publication.http.HTTPResponse.handleException formats the error as HTML and calls self.setResult, without touching the Content-Type header. This may cause an exception inside setResult:

      File ".../zope3/src/zope/app/publication/zopepublication.py", line 355, in handleException
        response.handleException(exc_info)
      File ".../zope3/src/zope/publisher/http.py", line 901, in handleException
        self.setResult(body)
      File ".../zope3/src/zope/publisher/http.py", line 817, in setResult body, headers = self._implicitResult(result)
      File ".../zope3/src/zope/publisher/http.py", line 861, in _implicitResult
        raise ValueError(
    ValueError: Unicode results must have a text content type.

Suggested fix:

Index: var/src/zope3/src/zope/publisher/http.py
===================================================================
--- var/src/zope3/src/zope/publisher/http.py (revision 69362)
+++ var/src/zope3/src/zope/publisher/http.py (working copy)
@@ -897,6 +897,7 @@
         self.setStatus(tname)

         body = self._html(title, "A server error occurred." )
+ self.setHeader('Content-Type', 'text/html')
         self.setResult(body)

It needs a unit test before it can be applied.

Tags: core issue
Revision history for this message
Martijn Faassen (faassen) wrote :

I ran into this issue as well, through http://www.zope.org/Collectors/Zope3-dev/558. See also some discussion there for details. Odd thing is I attempted the Content-Type fix, but had it not working for me. I'll try again.

Revision history for this message
Martijn Faassen (faassen) wrote :

Changes: submitter email, edited transcript, importance (medium => critical)

Revision history for this message
Martijn Faassen (faassen) wrote :

The Content-Type fix actually does "work" for me, but we realized that things may show up in the error reporting utility that don't show up in the SiteError log.

Revision history for this message
Martijn Faassen (faassen) wrote :

To expand on that, the "working" fix makes things be visible in the error utility as before, but *nothing* whatsoever will show up in the SiteError log (thus STDOUT in the standard configuration) to indicate that there was an error.

Revision history for this message
Rocky Burt (rocky-burt) wrote :

Getting a bit off-topic. Think for this bug we should just get handleException's content-type stuff right :)

Changed in zope3:
status: Unconfirmed → Confirmed
Revision history for this message
Dmitry Vasiliev (hdima) wrote :

I'll commit the suggested fix and look into the error reporting issue.

Revision history for this message
Dmitry Vasiliev (hdima) wrote :

Fixed on the trunk at revision 75799. The error reporting issue needs further investigation. I'll look at it later.

Revision history for this message
Philipp von Weitershausen (philikon) wrote :

We've had two betas since this fix has been committed, therefore setting status to Fix Released.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.