def writeHeaders(self):
"""Write headers to the response stream. Used internally."""
if self._committed:
print "response.writeHeaders called when already committed"
return
# make sure the status header comes first
if 'Status' in self._headers:
# store and temporarily delete status
status = self._headers['Status']
del self._headers['Status']
else:
# invent meaningful status
status = '302 Found' if 'Location' in self._headers else '200 OK'
head = ['Status: %s' % status]
head.extend(map(lambda h: '%s: %s' % h, self._headers.items()))
self._headers['Status'] = status # restore status
head.extend(map(lambda c: 'Set-Cookie: %s' % c.headerValue(),
self._cookies.values()))
head.extend(['']*2) # this adds one empty line
head = '\r\n'.join(head)
self._strmOut.prepend(head)
评论列表
文章目录