Commit b4d798b4 authored by Amos Latteier's avatar Amos Latteier

Added check for streaming responses when determing whether to add a...

Added check for streaming responses when determing whether to add a content-length header and setting a 204 response. This should fix the problem of streaming response having content-length 0 respone headers. Thanks to Toby Dickenson.
parent 89fa81ef
...@@ -113,6 +113,8 @@ class ZServerHTTPResponse(HTTPResponse): ...@@ -113,6 +113,8 @@ class ZServerHTTPResponse(HTTPResponse):
_http_connection='close' _http_connection='close'
_server_version='Zope/2.0 ZServer/2.0' _server_version='Zope/2.0 ZServer/2.0'
_streaming=0
def __str__(self, def __str__(self,
html_search=regex.compile('<html>',regex.casefold).search, html_search=regex.compile('<html>',regex.casefold).search,
): ):
...@@ -141,15 +143,19 @@ class ZServerHTTPResponse(HTTPResponse): ...@@ -141,15 +143,19 @@ class ZServerHTTPResponse(HTTPResponse):
body=self.body body=self.body
# set 204 (no content) status if 200 and response is empty # set 204 (no content) status if 200 and response is empty
# and not streaming
if not headers.has_key('content-type') and \ if not headers.has_key('content-type') and \
not headers.has_key('content-length') and \ not headers.has_key('content-length') and \
not headers.has_key('transfer-encoding') and \ not headers.has_key('transfer-encoding') and \
not self._streaming and \
self.status == 200: self.status == 200:
self.setStatus('nocontent') self.setStatus('nocontent')
# add content length if not transfer encoded # add content length if not transfer encoded
# and not streaming
if not headers.has_key('content-length') and \ if not headers.has_key('content-length') and \
not headers.has_key('transfer-encoding'): not headers.has_key('transfer-encoding') and \
not self._streaming:
self.setHeader('content-length',len(body)) self.setHeader('content-length',len(body))
headersl=[] headersl=[]
...@@ -245,6 +251,7 @@ class ZServerHTTPResponse(HTTPResponse): ...@@ -245,6 +251,7 @@ class ZServerHTTPResponse(HTTPResponse):
self._templock=thread.allocate_lock() self._templock=thread.allocate_lock()
except: pass except: pass
self._streaming=1
stdout.write(str(self)) stdout.write(str(self))
self._wrote=1 self._wrote=1
......
...@@ -113,6 +113,8 @@ class ZServerHTTPResponse(HTTPResponse): ...@@ -113,6 +113,8 @@ class ZServerHTTPResponse(HTTPResponse):
_http_connection='close' _http_connection='close'
_server_version='Zope/2.0 ZServer/2.0' _server_version='Zope/2.0 ZServer/2.0'
_streaming=0
def __str__(self, def __str__(self,
html_search=regex.compile('<html>',regex.casefold).search, html_search=regex.compile('<html>',regex.casefold).search,
): ):
...@@ -141,15 +143,19 @@ class ZServerHTTPResponse(HTTPResponse): ...@@ -141,15 +143,19 @@ class ZServerHTTPResponse(HTTPResponse):
body=self.body body=self.body
# set 204 (no content) status if 200 and response is empty # set 204 (no content) status if 200 and response is empty
# and not streaming
if not headers.has_key('content-type') and \ if not headers.has_key('content-type') and \
not headers.has_key('content-length') and \ not headers.has_key('content-length') and \
not headers.has_key('transfer-encoding') and \ not headers.has_key('transfer-encoding') and \
not self._streaming and \
self.status == 200: self.status == 200:
self.setStatus('nocontent') self.setStatus('nocontent')
# add content length if not transfer encoded # add content length if not transfer encoded
# and not streaming
if not headers.has_key('content-length') and \ if not headers.has_key('content-length') and \
not headers.has_key('transfer-encoding'): not headers.has_key('transfer-encoding') and \
not self._streaming:
self.setHeader('content-length',len(body)) self.setHeader('content-length',len(body))
headersl=[] headersl=[]
...@@ -245,6 +251,7 @@ class ZServerHTTPResponse(HTTPResponse): ...@@ -245,6 +251,7 @@ class ZServerHTTPResponse(HTTPResponse):
self._templock=thread.allocate_lock() self._templock=thread.allocate_lock()
except: pass except: pass
self._streaming=1
stdout.write(str(self)) stdout.write(str(self))
self._wrote=1 self._wrote=1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment