def checkPersistence(self, request, version):
"""Check if the channel should close or not."""
connection = request.getHeader('connection')
if connection:
tokens = map(str.lower, connection.split(' '))
else:
tokens = []
# HTTP 1.0 persistent connection support is currently disabled,
# since we need a way to disable pipelining. HTTP 1.0 can't do
# pipelining since we can't know in advance if we'll have a
# content-length header, if we don't have the header we need to close the
# connection. In HTTP 1.1 this is not an issue since we use chunked
# encoding if content-length is not available.
#if version == "HTTP/1.0":
# if 'keep-alive' in tokens:
# request.setHeader('connection', 'Keep-Alive')
# return 1
# else:
# return 0
if version == "HTTP/1.1":
if 'close' in tokens:
request.setHeader('connection', 'close')
return 0
else:
return 1
else:
return 0
评论列表
文章目录