mirror of https://git.48k.eu/ogclient
#1000 Fix ogClient HTTP length handling
Irina reports that "Partition assistant"/"Asistente de particionado" is not working. This is happening because ogClient is not reading the full data ogServer sends when the entire HTTP PDU is larger than 1024. However, ogClient should read the whole message, reading until read data length is greater or equal to "Content-Length" header value. ogClient fails to obtain "Content-Length" value because is looking for "content-length", be aware of the case sensitivity. It also needs to take into account the header length because read data length also includes headers. This patch updates ogClient to: 1) look for "Content-Length instead of "content-length". 2) compare read date length with content length plus headers length.more_events
parent
0593119352
commit
36b5064970
|
@ -55,6 +55,7 @@ class ogClient:
|
|||
self.data = ""
|
||||
self.trailer = False
|
||||
self.content_len = 0
|
||||
self.header_len = 0
|
||||
|
||||
try:
|
||||
self.sock.connect((self.ip, self.port))
|
||||
|
@ -98,23 +99,27 @@ class ogClient:
|
|||
request = restRequest()
|
||||
|
||||
if not self.trailer:
|
||||
if self.data.find("\r\n") > 0:
|
||||
header_len = self.data.find("\r\n")
|
||||
if header_len > 0:
|
||||
# https://stackoverflow.com/questions/4685217/parse-raw-http-headers
|
||||
request_line, headers_alone = self.data.split('\n', 1)
|
||||
headers = email.message_from_file(StringIO(headers_alone))
|
||||
|
||||
if 'content-length' in headers.keys():
|
||||
self.content_len = int(headers['content-length'])
|
||||
if 'Content-Length' in headers.keys():
|
||||
self.content_len = int(headers['Content-Length'])
|
||||
|
||||
self.trailer = True
|
||||
# Add 2 because self.data.find("\r\n") does not count "\r\n" for the length
|
||||
self.header_len = header_len + 2
|
||||
|
||||
if self.trailer and len(self.data) >= self.content_len:
|
||||
if self.trailer and (len(self.data) >= self.content_len + self.header_len):
|
||||
request.parser(self.data)
|
||||
self.ogrest.process_request(request, self)
|
||||
|
||||
# Cleanup state information from request
|
||||
self.data = ""
|
||||
self.content_len = 0
|
||||
self.header_len = 0
|
||||
self.trailer = False
|
||||
|
||||
def disconnect(self):
|
||||
|
|
Loading…
Reference in New Issue