Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2524 (closed defect: migrated)

Opened 9 years ago

Last modified 8 years ago

problem raising HTTP exceptions in @expose decorated controller

Reported by: nlaurance Owned by:
Priority: normal Milestone: 2.1
Component: TurboGears Version: 2.1
Severity: normal Keywords:


I try to test a controller that raises a HTTPNoContent Error with a self.app.get(url, status=204) and I get

* AssertionError?: Content-Type header found in a 204 response,

which must not return content. so it seems the controller sets a content-type header where it should not

controller looks like

@expose('templates.get_one', content_type='text/xml') def get_one(self,id, kwargs):

for some reason:

raise HTTPNoContent # this is HTTP error with code 204

test is like

resp = self.app.get('/items/3', status=204)

but the @expose decorator acts too soon and set a content-type header

in tg/decorators L 279+

if content_type is None:

if engine == 'json':

content_type = 'application/json'


content_type = 'text/html'

still in Webtest/lint.py L401+

def check_content_type(status, headers):

code = int(status.split(None, 1)[0]) # @@: need one more person to verify this interpretation of RFC


#  http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html NO_MESSAGE_BODY = (201, 204, 304) NO_MESSAGE_TYPE = (204, 304) for name, value in headers:

if name.lower() == 'content-type':

if code not in NO_MESSAGE_TYPE:


assert 0, (("Content-Type header found in a %s response, "

"which must not return content.") % code)

if code not in NO_MESSAGE_BODY:

assert 0, "No Content-Type header found in headers (%s)" %


Change History

comment:1 Changed 9 years ago by percious

  • Version changed from 2.0b7 to 2.1
  • Milestone changed from __unclassified__ to 2.1

comment:2 Changed 8 years ago by pedersen

  • Status changed from new to closed
  • Resolution set to migrated
Note: See TracTickets for help on using tickets.