[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/HTTP - HTTPResponse.py:1.1.2.8
Shane Hathaway
shane@digicool.com
Mon, 26 Nov 2001 18:11:39 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/HTTP
In directory cvs.zope.org:/tmp/cvs-serv15972/lib/python/Zope/Publisher/HTTP
Modified Files:
Tag: Zope-3x-branch
HTTPResponse.py
Log Message:
- Added logging to HTTPServer2.
- Created and used an "Adjustments" module.
- Kill zombie HTTP connections.
=== Zope3/lib/python/Zope/Publisher/HTTP/HTTPResponse.py 1.1.2.7 => 1.1.2.8 ===
_wrote_headers = 0
_streaming = 0
+ status = 200
+ reason = 'Ok'
def __init__(self, payload, outstream, header_output=None):
@@ -161,8 +163,7 @@
reason = status_reasons[status]
else:
reason = 'Unknown'
- self.setHeader('Status', "%d %s" % (status,str(reason)))
- self.errmsg = reason
+ self.reason = reason
def setHeader(self, name, value, literal=0):
'''
@@ -307,10 +308,9 @@
return cookie_list
- def getStatusAndHeaders(self):
+ def getHeaders(self):
"""
- Returns a tuple of the status and a mapping of correctly-cased
- header names to values.
+ Returns a mapping of correctly-cased header names to values.
"""
res = {}
headers = self.headers
@@ -333,20 +333,11 @@
l=key.find('-',start)
res[key] = val
- if res.has_key('Status'):
- status = res['Status']
- del res['Status']
- else:
- if not self._streaming and not self.body:
- status = '204 No Content'
- else:
- status = '200 OK'
-
- return status, res
+ return res
- def getHeaderText(self, status, m):
- lst = ['Status: %s' % status]
+ def getHeaderText(self, m):
+ lst = ['Status: %s %s' % (self.status, self.reason)]
lst.extend(map(lambda x: '%s: %s' % x, m.items()))
lst.extend(self._cookie_list())
accum = self.accumulated_headers
@@ -356,11 +347,11 @@
def outputHeaders(self):
- status, m = self.getStatusAndHeaders()
+ m = self.getHeaders()
header_output = self.header_output
if header_output is not None:
# Use the IHeaderOutput interface.
- header_output.setResponseStatus(status)
+ header_output.setResponseStatus(self.status, self.reason)
header_output.setResponseHeaders(m)
cookies = self._cookie_list()
if cookies:
@@ -370,7 +361,7 @@
header_output.appendResponseHeaders(accum)
else:
# Write directly to outstream.
- s = self.getHeaderText(status, m)
+ s = self.getHeaderText(m)
self.outstream.write(s)
@@ -379,8 +370,8 @@
Debugging output. Does not include headers added for connection
control.
"""
- status, m = self.getStatusAndHeaders()
- return self.getHeaderText(status, m) + self.body
+ m = self.getHeaders()
+ return self.getHeaderText(m) + self.body
def write(self, data):