<div>Thanks Philipp, here is the unified diffs.</div>
<div>--- httptask.py.orig Fri Jan 06 02:15:48 2006<br>+++ httptask.py Thu Sep 21 17:31:17 2006<br>@@ -126,6 +126,15 @@<br> else:<br> close_it = 1<br> elif version == '1.1':<br>+ #modified by Simon
<br>+ thisflag = False<br>+ for each in self.accumulated_headers:<br>+ if each.lower() == 'connection: keep-alive':<br>+ thisflag = True<br>+ break
<br>+ if thisflag == False:<br>+ close_it = 1<br>+<br> if connection == 'close':<br> close_it = 1<br> elif 'Transfer-Encoding' in response_headers:<br>@@ -134,8 +143,15 @@
<br> elif self.status == '304':<br> # Replying with headers only.<br> pass<br>+ #modified by simon<br> elif not ('Content-Length' in response_headers):<br>
- close_it = 1<br>+ thisflag = False<br>+ for each in self.accumulated_headers:<br>+ if each[:14].lower() == 'content-length':<br>+ thisflag = True
<br>+ break<br>+ if thisflag == False: #only content_length not exist in accumulated headers too<br>+ close_it = 1<br> else:<br> # Close if unrecognized HTTP version.
<br> close_it = 1<br><br> </div>
<div><span class="gmail_quote">On 9/21/06, <b class="gmail_sendername">Philipp von Weitershausen</b> <<a href="mailto:philipp@weitershausen.de">philipp@weitershausen.de</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Simon Hang wrote:<br>> How about below changes?<br><br>There aren't many of us who know the zope.server
code that well,<br>unfortunately. This is one of the reasons we want to "get out of the<br>server business".<br><br>That said, it would *much* easier to understand what you're trying to do<br>if you provided *unified diffs* (create them with "svn diff" or "diff -u").
<br><br>Philipp<br><br><br>><br>> in httptask.py<br>><br>> def prepareResponseHeaders(self):<br>> version = self.version<br>> # Figure out whether the connection should be closed.<br>
> connection = self.request_data.headers.get('CONNECTION', '').lower()<br>> close_it = 0<br>> response_headers = self.response_headers<br>><br>> if version == '1.0':<br>> if connection == 'keep-alive':
<br>> if not ('Content-Length' in response_headers):<br>> close_it = 1<br>> else:<br>> response_headers['Connection'] = 'Keep-Alive'<br>> else:
<br>> close_it = 1<br>> elif version == '1.1':<br>> #insert by Simon<br>> thisflag = False<br>> for each in self.accumulated_headers:<br>> if
each.lower() == 'connection: keep-alive':<br>> thisflag = True<br>> break<br>> if thisflag == False:<br>> close_it = 1<br>> #end of insert
<br>> if connection == 'close':<br>> close_it = 1<br>> elif 'Transfer-Encoding' in response_headers:<br>> if not response_headers['Transfer-Encoding'] == 'chunked':
<br>> close_it = 1<br>> elif self.status == '304':<br>> # Replying with headers only.<br>> pass<br>> #insert by simon<br>> elif not ('Content-Length' in response_headers):
<br>> thisflag = False<br>> for each in self.accumulated_headers:<br>> if each[:14].upper() == 'CONTENT-LENGTH':<br>> thisflag = True
<br>> break<br>> if thisflag == False: #only CONTENT_LENGTH not exist in<br>> accumulated headers too<br>><br>> #end of insert<br>> close_it = 1
<br>> else:<br>> # Close if unrecognized HTTP version.<br>> close_it = 1<br>><br>> self.close_on_finish = close_it<br>> if close_it:<br>> self.response_headers
['Connection'] = 'close'<br>><br>><br>><br>><br>> On 9/19/06, *Simon Hang*<br>> <<a href="mailto:hangzhiyun@gmail.com">hangzhiyun@gmail.com</a><br>> <mailto:<a href="mailto:hangzhiyun@gmail.com">
hangzhiyun@gmail.com</a>>> wrote:<br>><br>> Dear all,<br>><br>> While I was exploring my options to implement NTLM authentication, I<br>> found some strange behavior of Zope HTTP server.<br>
><br>> in zope.server.http.wsgihttpserver.WSGIHTTPServer,<br>> It use below function to handle response's head:<br>><br>> def start_response(status, headers):<br>> # Prepare the headers for output
<br>> status, reason = re.match('([0-9]*) (.*)', status).groups()<br>> task.setResponseStatus(status, reason)<br>> task.appendResponseHeaders(['%s: %s' % i for i in headers])
<br>><br>> # Return the write method used to write the response data.<br>> return fakeWrite<br>><br>> The result is all response's head from the content part of program<br>
> will be stored in task.accumulated_headers. See below function from<br>> zope.server.http.httptask.HTTPTask.<br>><br>> def appendResponseHeaders(self, lst):<br>> """See
zope.publisher.interfaces.http.IHeaderOutput"""<br>> accum = self.accumulated_headers<br>> if accum is None:<br>> self.accumulated_headers = accum = []<br>>
accum.extend(lst)<br>><br>> But, the problem is while httptask to determin whether to close the<br>> connection or not, it use below code. The code is only checking<br>> self.response_headers which has nothing to do with the response our
<br>> application generated. So zope ends up to disconnect connection for<br>> each single request.<br>><br>> def prepareResponseHeaders(self):<br>> version = self.version<br>> # Figure out whether the connection should be closed.
<br>> connection = self.request_data.headers.get('CONNECTION',<br>> '').lower()<br>> close_it = 0<br>> response_headers = self.response_headers<br>><br>> if version == '
1.0':<br>> if connection == 'keep-alive':<br>> if not ('Content-Length' in response_headers):<br>> close_it = 1<br>> else:<br>> response_headers['Connection'] = 'Keep-Alive'
<br>> else:<br>> close_it = 1<br>> elif version == '1.1':<br>> thisflag = False<br>><br>> if connection == 'close':<br>> close_it = 1
<br>> elif 'Transfer-Encoding' in response_headers:<br>> if not response_headers['Transfer-Encoding'] ==<br>> 'chunked':<br>> close_it = 1<br>> elif
self.status == '304':<br>> # Replying with headers only.<br>> pass<br>> elif not ('Content-Length' in response_headers):<br>> close_it = 1
<br>> else:<br>> # Close if unrecognized HTTP version.<br>> close_it = 1<br>><br>> self.close_on_finish = close_it<br>> if close_it:<br>
> self.response_headers['Connection'] = 'close'<br>><br>><br>> Can somebody tell me why the thing is implement like this, is there<br>> special reason to do this? Or can we change it a little bit to let
<br>> zope support persistence connection?<br>><br>> Thanks,<br>> Simon<br>><br>><br>><br>><br>><br>> ------------------------------------------------------------------------<br>>
<br>> _______________________________________________<br>> Zope3-users mailing list<br>> <a href="mailto:Zope3-users@zope.org">Zope3-users@zope.org</a><br>> <a href="http://mail.zope.org/mailman/listinfo/zope3-users">
http://mail.zope.org/mailman/listinfo/zope3-users</a><br><br>_______________________________________________<br>Zope3-users mailing list<br><a href="mailto:Zope3-users@zope.org">Zope3-users@zope.org</a><br><a href="http://mail.zope.org/mailman/listinfo/zope3-users">
http://mail.zope.org/mailman/listinfo/zope3-users</a><br></blockquote></div><br>