[Twisted-Python] twcgi duplicate Content-Type

Laurens Van Houtven lvh at laurensvh.be
Fri Dec 31 18:13:06 MST 2010


Hi!


I'm using twcgi to serve a Fossil repository through CGI (it's that or
xinetd). For some reason, Chrome wasn't rendering the CSS. Looking at
the HTTP response headers for the GET request for the CSS file, I saw
this:

HTTP/1.1 200 OK
Date: Sat, 01 Jan 2011 00:14:58 GMT
Content-Length: 13484
Expires: Sat, 8 Jan 2011 00:14:58 GMT
Content-Type: text/html
Content-Type: text/css; charset=utf-8
Server: TwistedWeb/10.2.0

I'm pretty sure duplicate Content-Type headers aren't supposed to happen.

After some digging, I'm convinced the Server, Date and the first
Content-Type are the default values set in t.w.server [1]. Meanwhile,
twcgi [2] users self.request.responseHeaders.addRawHeader, so the
default header is never overwritten.

I'm pretty sure that's not supposed to happen, but I'm not sure what
the correct way to fix this is. Options:

1) Should a list of things that need setRawHeader be introduced?
2) Should setRawHeader be the default, and instead have a list of
things that need addRawHeader?
3) Should that twcgi code use request.setHeader instead, like the
t.w.server code?

I have a feeling it's the last option. but like I said, I'm not sure.

[1] http://twistedmatrix.com/trac/browser/tags/releases/twisted-10.2.0/twisted/web/server.py#L118
[2] http://twistedmatrix.com/trac/browser/tags/releases/twisted-10.2.0/twisted/web/twcgi.py#L308


cheers and happy new year,
lvh




More information about the Twisted-Python mailing list