[Twisted-Python] Possible bug in twisted/protocols/http.py?

Carl Waldbieser waldbie at attglobal.net
Sun Dec 7 19:44:26 EST 2003

I am using:
Twisted 1.1.0.
Python 2.3.2
Running on WinXP

I recently set up a wireless network at home (1 WinXP system and 1 Win98
system), and because I have a dial-up connection to the Internet, I wanted
to set up an HTTP proxy sever so both computers could browse the web
simultaneously.  I tried a bunch of different free applications that seemed
to fit the bill, but many seemed either too complicated, or easy but just
not configurable enough.

While googling, I came across an old message where someone was very
impressed with how easy it was to create a web proxy using twisted.  Since I
am a big Python fan, I thought I'd give it a go.  It was remarkably easy to
hack something together, and initially, everything seemed to work pretty
well.  However, after browsing one site, I noticed a buch of errors popping
up in my console box.  Both seemed to originate from http.py (in
/twisted/protocols directory).

The first (around line 314) was that the StringTransport class was being
asked to make a loseConnection() method invocation, but the class didn't
have one.  I seemed to get around that problem by adding that method to the
class as a no-op.

The second (around line 350) was caused by the following statement:

key, val = line.split(': ', 1)

I believe the line has something to do with parsing the request headers.
The problem was that the header was being sent like "name:value" with no
space after the colon.  This caused the tuple unpacking to blow up.  I
googled for information about what comprises a valid HTTP request, and came
up with the following:

In rfc2616
concerning HTTP/1.1
in section 4.2
Direct quote: "The field value MAY be preceded by any amount of LWS, though
a single SP is preferred."

I have no idea if this is the final word on HTTP headers, but it does look
like maybe the lack of a space should be accepted more gracefully in this

I am not sure if these are actual bugs (the proxy didn't crash in any
event).  I thought I ought to let someone, know, though.

Carl Waldbieser

More information about the Twisted-Python mailing list