Update webutils

parent b461ab22
......@@ -73,6 +73,7 @@ class HTTPPageGetter(client.HTTPPageGetter):
rectimeout = 15
checkTimeout = False
expect100 = False
received100 = False
def sendCommand(self, command, path):
version=b' HTTP/1.0\r\n'
......@@ -90,6 +91,7 @@ class HTTPPageGetter(client.HTTPPageGetter):
return client.HTTPPageGetter.rawDataReceived(self, *args, **kwargs)
def connectionMade(self, *args, **kwargs):
self.lastrec = time.time()
if self.checkTimeout:
try:
......@@ -102,8 +104,6 @@ class HTTPPageGetter(client.HTTPPageGetter):
auth = "Basic " + base64.encodestring(cred).replace('\012','')
#self.sendHeader('Authorization', auth)
self.factory.headers['Authorization'] = auth
if self.expect100:
self.factory.headers['Expect'] = '100-continue'
self.checkTimeout = task.LoopingCall(self.timeoutCheck)
self.checkTimeout.start(1)
method = getattr(self.factory, 'method', b'GET')
......@@ -116,14 +116,15 @@ class HTTPPageGetter(client.HTTPPageGetter):
host = self.factory.host
self.sendHeader(b'Host', self.factory.headers.get(b"host", host))
self.sendHeader(b'User-Agent', self.factory.agent)
data = getattr(self.factory, 'postdata', None)
if data is not None:
self.sendHeader(b"Content-Length", intToBytes(len(data)))
cookieData = []
contenttypehdr = False
for (key, value) in self.factory.headers.items():
if key.lower() not in self._specialHeaders:
# we calculated it on our own
if key.lower() == 'content-type':
contenttypehdr = (key, value)
else:
self.sendHeader(key, value)
if key.lower() == b'cookie':
cookieData.append(value)
......@@ -131,6 +132,17 @@ class HTTPPageGetter(client.HTTPPageGetter):
cookieData.append(cookie + b'=' + cookval)
if cookieData:
self.sendHeader(b'Cookie', b'; '.join(cookieData))
data = getattr(self.factory, 'postdata', None)
if data is not None:
self.sendHeader(b"Content-Length", intToBytes(len(data)))
if self.expect100:
self.sendHeader('Expect', '100-continue')
if contenttypehdr:
key, value = contenttypehdr
self.sendHeader(key, value)
self.endHeaders()
self.headers = {}
......@@ -159,11 +171,21 @@ class HTTPPageGetter(client.HTTPPageGetter):
except:
pass
def lineReceived(self, line):
client.HTTPPageGetter.lineReceived(self, line)
if self.expect100 and self.received100:
self.received100=False
self.setLineMode()
def handleStatus_100(self):
self.received100 = True
self.firstLine = True
self.__buffer = None
if self.expect100:
self._writeData()
else:
self.handleStatus_400()
self.setLineMode()
def handleStatus_404(self):
self.handleStatusDefault()
......
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