![](https://secure.gravatar.com/avatar/a0d8b345042b7b2d583ec688f0c92396.jpg?s=120&d=mm&r=g)
I've written an http proxy using twisted. It works fine, except when proxying an HTTP 204 response. The handleStatus, handleHeader and handleEndHeaders all get called. Then the process just hangs for 10+ seconds (presumably timing out). Then handleResponseEnd gets called (never calling handleResponsePart). All of this is expected, except for the hanging part. Anyone have any ideas what's going on here? Thanks, Brian
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Fri, 24 Apr 2009 11:55:20 -0700, Brian Kuhn <bnkuhn@gmail.com> wrote:
I've written an http proxy using twisted. It works fine, except when proxying an HTTP 204 response. The handleStatus, handleHeader and handleEndHeaders all get called. Then the process just hangs for 10+ seconds (presumably timing out). Then handleResponseEnd gets called (never calling handleResponsePart).
All of this is expected, except for the hanging part. Anyone have any ideas what's going on here?
204 is "No Content". Quoting the RFC: The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields. This, despite the fact that a 204 response may include a content-length header with a non-zero value. Make sure you're handling this properly. Jean-Paul
![](https://secure.gravatar.com/avatar/a0d8b345042b7b2d583ec688f0c92396.jpg?s=120&d=mm&r=g)
I understand what a 204 is. It appears though that the framework is hanging on them...not my code. Twisted calls my handleEndHeaders method, then hangs for awhile, then calls my handleResponseEnd method. Perhaps there is something I need to do in the handleStatus method to preempt this behavior. Any idea how I can tell Twisted to not timeout waiting for content that will never come? -Brian On Fri, Apr 24, 2009 at 12:01 PM, Jean-Paul Calderone <exarkun@divmod.com>wrote:
On Fri, 24 Apr 2009 11:55:20 -0700, Brian Kuhn <bnkuhn@gmail.com> wrote:
I've written an http proxy using twisted. It works fine, except when proxying an HTTP 204 response. The handleStatus, handleHeader and handleEndHeaders all get called. Then the process just hangs for 10+ seconds (presumably timing out). Then handleResponseEnd gets called (never calling handleResponsePart).
All of this is expected, except for the hanging part. Anyone have any ideas what's going on here?
204 is "No Content". Quoting the RFC:
The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.
This, despite the fact that a 204 response may include a content-length header with a non-zero value. Make sure you're handling this properly.
Jean-Paul
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Fri, 24 Apr 2009 12:40:33 -0700, Brian Kuhn <bnkuhn@gmail.com> wrote:
I understand what a 204 is. It appears though that the framework is hanging on them...not my code. Twisted calls my handleEndHeaders method, then hangs for awhile, then calls my handleResponseEnd method.
Perhaps there is something I need to do in the handleStatus method to preempt this behavior. Any idea how I can tell Twisted to not timeout waiting for content that will never come?
I dunno, maybe. It's hard to know without being able to see your code. I suppose you have an HTTPClient subclass? Or maybe a ProxyClient sub- class? Likely you should be getting a `handleResponseEnd` when the connection is closed. If the server never closes the connection, then perhaps you'll never get `handleResponseEnd`, I'm not sure. Jean-Paul
![](https://secure.gravatar.com/avatar/a0d8b345042b7b2d583ec688f0c92396.jpg?s=120&d=mm&r=g)
Now that you mention it, this probably does have something to do with the server keeping the connection alive since the client is sending keep-alive headers... Keep-Alive : 300 Proxy-Connection: keep-alive I'm going to investigate this a little further before I post my code. I'll let you know what I find out. Thanks, Brian On Fri, Apr 24, 2009 at 1:01 PM, Jean-Paul Calderone <exarkun@divmod.com>wrote:
On Fri, 24 Apr 2009 12:40:33 -0700, Brian Kuhn <bnkuhn@gmail.com> wrote:
I understand what a 204 is. It appears though that the framework is hanging on them...not my code. Twisted calls my handleEndHeaders method, then hangs for awhile, then calls my handleResponseEnd method.
Perhaps there is something I need to do in the handleStatus method to preempt this behavior. Any idea how I can tell Twisted to not timeout waiting for content that will never come?
I dunno, maybe. It's hard to know without being able to see your code. I suppose you have an HTTPClient subclass? Or maybe a ProxyClient sub- class? Likely you should be getting a `handleResponseEnd` when the connection is closed. If the server never closes the connection, then perhaps you'll never get `handleResponseEnd`, I'm not sure.
Jean-Paul
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
![](https://secure.gravatar.com/avatar/a0d8b345042b7b2d583ec688f0c92396.jpg?s=120&d=mm&r=g)
I got it to work by stripping the keep-alive headers and manually calling my handleResponseEnd when handleEndHeaders is called for requests having Content-Length: 0. I'd still like to keep connections alive if possible, so I may do something more sophisticated in the future, but this will do for now. Thanks for the help Jean-Paul. -Brian On Fri, Apr 24, 2009 at 2:01 PM, Brian Kuhn <bnkuhn@gmail.com> wrote:
Now that you mention it, this probably does have something to do with the server keeping the connection alive since the client is sending keep-alive headers...
Keep-Alive : 300 Proxy-Connection: keep-alive
I'm going to investigate this a little further before I post my code. I'll let you know what I find out.
Thanks, Brian
On Fri, Apr 24, 2009 at 1:01 PM, Jean-Paul Calderone <exarkun@divmod.com>wrote:
On Fri, 24 Apr 2009 12:40:33 -0700, Brian Kuhn <bnkuhn@gmail.com> wrote:
I understand what a 204 is. It appears though that the framework is hanging on them...not my code. Twisted calls my handleEndHeaders method, then hangs for awhile, then calls my handleResponseEnd method.
Perhaps there is something I need to do in the handleStatus method to preempt this behavior. Any idea how I can tell Twisted to not timeout waiting for content that will never come?
I dunno, maybe. It's hard to know without being able to see your code. I suppose you have an HTTPClient subclass? Or maybe a ProxyClient sub- class? Likely you should be getting a `handleResponseEnd` when the connection is closed. If the server never closes the connection, then perhaps you'll never get `handleResponseEnd`, I'm not sure.
Jean-Paul
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
participants (2)
-
Brian Kuhn
-
Jean-Paul Calderone