summaryrefslogtreecommitdiffstats
path: root/src/ogClient.py
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2020-08-24 14:45:26 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-08-25 10:55:45 +0200
commit36b5064970ea42a06a9ac9f8d91d45da00e45f89 (patch)
tree3cb50dc4306b77cbe1135332283e058c9f015fff /src/ogClient.py
parent0593119352b24c0372c0bd222641789c01fc4c5c (diff)
#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.
Diffstat (limited to 'src/ogClient.py')
-rw-r--r--src/ogClient.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/ogClient.py b/src/ogClient.py
index 46ab9a2..5b42858 100644
--- a/src/ogClient.py
+++ b/src/ogClient.py
@@ -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):