[Twisted-web] Close TCP Connection Using web resource.Resource

Michael Toop michaelt at voxtelecom.co.za
Thu May 7 15:22:47 EDT 2009

Hi Drew,
 Thanks for the feedback. 
 There are no headers in our server that annotate this.  Great idea though, I didn't realise that this was an option.  What I will try is insert the "Connection: close" header in & see if the client responds with this (hopefully Twisted will then in turn close the connection).
 FYI here are the headers in current server:
Content-Type: text/xml; charset=ISO-8859-1
Host: vvvaacs.co.za
User-Agent: Thomson_cwmp-engine/r6.2.W.1
Transfer-Encoding: chunked

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Thu, 07 May 2009 12:42:00 GMT
Content-Type: text/xml; charset=iso-8859-1
Server: TwistedWeb/8.2.0



From: twisted-web-bounces at twistedmatrix.com on behalf of Drew Smathers
Sent: Thu 5/7/2009 08:47 PM
To: Twisted Web World
Subject: Re: [Twisted-web] Close TCP Connection Using web resource.Resource

On Thu, May 7, 2009 at 2:05 PM, Michael Toop <michaelt at voxtelecom.co.za> wrote:
> Hi,
>  We are struggling to close a TCP connection using web
> resource.Resource (the TR69 SOAP spec. mandates that we close the connection
> when we are done).
>  Our site is served in a TCP reactor & uses the NOT_DONE_YET variable in the
> def render_POST method.  We close the render_POST with a
> request.write('data') & a request.finish() but the connection stays open,
> stub code below.
>  We are not sure if it is the fact that we are using chunked encoding or if
> this is a bug?
>  Please assist.
> Warm Regards,
> Michael Toop
> def render_POST(self,request):
>    ...do stuff
>   d = getSoapText(request)
>   d.addCallback(request.write)
>   d.addCallback(request.close())
>   return server.NOT_DONE_YET

I'm guessing it was a typo above and should be something like:

  d.addCallback(lambda ign: request.finish())

Also, I don't think request.finish necessarily entails closing the
connection as this depends upon whether or the channel is persistent
via keep-alive.

I think the rules for connection persistence in twisted.web are:

HTTP 1.0:
HTTP 1.1 and "Connection: close" in request headers:          non-persistent
HTTP 1.1 and "Connection: close" NOT in request headers:   persistent


Twisted-web mailing list
Twisted-web at twistedmatrix.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 6283 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-web/attachments/20090507/8176a5d8/attachment.bin 

More information about the Twisted-web mailing list