Merge local changes.

This commit is contained in:
Stephan Erb 2009-11-13 08:58:00 +01:00
commit 3696e5296d
4 changed files with 16 additions and 6 deletions

View File

@ -462,6 +462,9 @@ class XMPPDispatcher(PlugIn):
# we have released dispatcher, so self._owner has no methods # we have released dispatcher, so self._owner has no methods
if not res: if not res:
return return
if 'remove_timeout' in self._owner.__dict__:
# When we receive data after we started disconnecting, Transport may
# already be plugged out
self._owner.remove_timeout() self._owner.remove_timeout()
for (_id, _iq) in self._expected.items(): for (_id, _iq) in self._expected.items():
if _iq is None: if _iq is None:

View File

@ -648,7 +648,8 @@ class NonBlockingHTTP(NonBlockingTCP):
# append currently received data to HTTP msg in buffer # append currently received data to HTTP msg in buffer
self.recvbuff = '%s%s' % (self.recvbuff or '', data) self.recvbuff = '%s%s' % (self.recvbuff or '', data)
statusline, headers, httpbody, self.recvbuff = self.parse_http_message(self.recvbuff) statusline, headers, httpbody, buffer_rest = self.parse_http_message(
self.recvbuff)
if not (statusline and headers and httpbody): if not (statusline and headers and httpbody):
log.debug('Received incomplete HTTP response') log.debug('Received incomplete HTTP response')
@ -668,6 +669,10 @@ class NonBlockingHTTP(NonBlockingTCP):
log.info('not enough bytes in HTTP response - %d expected, %d got' % log.info('not enough bytes in HTTP response - %d expected, %d got' %
(self.expected_length, len(self.recvbuff))) (self.expected_length, len(self.recvbuff)))
else: else:
# First part of buffer has been extraced and is going to be handled,
# remove it from buffer
self.recvbuff = buffer_rest
# everything was received # everything was received
self.expected_length = 0 self.expected_length = 0
@ -702,7 +707,7 @@ class NonBlockingHTTP(NonBlockingTCP):
headers.append('Connection: Keep-Alive') headers.append('Connection: Keep-Alive')
headers.append('\r\n') headers.append('\r\n')
headers = '\r\n'.join(headers) headers = '\r\n'.join(headers)
return('%s%s\r\n' % (headers, httpbody)) return('%s%s' % (headers, httpbody))
def parse_http_message(self, message): def parse_http_message(self, message):
''' '''
@ -711,6 +716,7 @@ class NonBlockingHTTP(NonBlockingTCP):
headers - dictionary of headers e.g. {'Content-Length': '604', headers - dictionary of headers e.g. {'Content-Length': '604',
'Content-Type': 'text/xml; charset=utf-8'}, 'Content-Type': 'text/xml; charset=utf-8'},
httpbody - string with http body) httpbody - string with http body)
http_rest - what is left in the message after a full HTTP header + body
''' '''
message = message.replace('\r','') message = message.replace('\r','')
splitted = message.split('\n\n') splitted = message.split('\n\n')

View File

@ -494,7 +494,7 @@ class P2PConnection(IdleObject, PlugIn):
self.disconnect() self.disconnect()
return True return True
def disconnect(self): def disconnect(self, message=''):
''' Closes the socket. ''' ''' Closes the socket. '''
gajim.idlequeue.remove_timeout(self.fd) gajim.idlequeue.remove_timeout(self.fd)
gajim.idlequeue.unplug_idle(self.fd) gajim.idlequeue.unplug_idle(self.fd)

View File

@ -262,9 +262,10 @@ class TestNonBlockingHTTP(AbstractTransportTest):
% payload % payload
message = "%s%s" % (header, body) message = "%s%s" % (header, body)
chunk1, chunk2, chunk3 = message[:20], message[20:73], message[73:] chunk1, chunk2, chunk3, chunk4 = message[:20], message[20:73], \
message[73:85], message[85:]
nextmessage_chunk = "\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/x" nextmessage_chunk = "\r\n\r\nHTTP/1.1 200 OK\r\nContent-Type: text/x"
chunks = (chunk1, chunk2, chunk3, nextmessage_chunk) chunks = (chunk1, chunk2, chunk3, chunk4, nextmessage_chunk)
transport.onreceive(self.expect_receive(body, msg='Failed: In chunks')) transport.onreceive(self.expect_receive(body, msg='Failed: In chunks'))
for chunk in chunks: for chunk in chunks: