Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77691b8

Browse files
committed
fix for that keepalive (not only IIS issue)
1 parent 75dc44d commit 77691b8

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

extra/keepalive/keepalive.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
prefer to see your error codes, then do.
6868
6969
"""
70+
from httplib import _CS_REQ_STARTED, _CS_REQ_SENT, CannotSendHeader
7071

7172
import threading
7273
import urllib2
@@ -113,6 +114,7 @@ def _get_connection_key(self, host):
113114
return (threading.currentThread(), host)
114115

115116
def _start_connection(self, h, req):
117+
h.clearheaders()
116118
try:
117119
if req.has_data():
118120
data = req.get_data()
@@ -289,7 +291,37 @@ def readlines(self, sizehint = 0):
289291
class HTTPConnection(httplib.HTTPConnection):
290292
# use the modified response class
291293
response_class = HTTPResponse
292-
294+
_headers = {}
295+
296+
def clearheaders(self):
297+
self._headers.clear()
298+
299+
def putheader(self, header, value):
300+
"""Send a request header line to the server.
301+
302+
For example: h.putheader('Accept', 'text/html')
303+
"""
304+
if self.__state != _CS_REQ_STARTED:
305+
raise CannotSendHeader()
306+
307+
self._headers[header] = value
308+
309+
310+
def endheaders(self):
311+
"""Indicate that the last header line has been sent to the server."""
312+
313+
if self.__state == _CS_REQ_STARTED:
314+
self.__state = _CS_REQ_SENT
315+
else:
316+
raise CannotSendHeader()
317+
318+
for header, value in self._headers.items():
319+
print header, value
320+
str = '%s: %s' % (header, value)
321+
self._output(str)
322+
323+
self._send_output()
324+
293325
#########################################################################
294326
##### TEST FUNCTIONS
295327
#########################################################################

0 commit comments

Comments
 (0)