Update webutils

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