From 36b5064970ea42a06a9ac9f8d91d45da00e45f89 Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Mon, 24 Aug 2020 14:45:26 +0200 Subject: #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. --- src/ogClient.py | 13 +++++++++---- 1 file 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): -- cgit v1.2.3-18-g5258