From e7a787cbc4e01e92be6e062e94211dca644fae0c Mon Sep 17 00:00:00 2001 From: Crypt0-M3lon Date: Fri, 8 Feb 2019 09:08:24 +0100 Subject: [PATCH] Fix socket timeout on HTTP POST requests Remaining size should be checked at the end of the loop, the current implementation hang when POST request Content-Lenght is 0. We want to check for Content-Length header only if we received full header. --- servers/HTTP.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/servers/HTTP.py b/servers/HTTP.py index 228e868..2d553a1 100644 --- a/servers/HTTP.py +++ b/servers/HTTP.py @@ -278,21 +278,20 @@ class HTTP(BaseRequestHandler): break data += buff remaining -= len(buff) - if remaining <= 0: - break #check if we recieved the full header if data.find('\r\n\r\n') != -1: #we did, now to check if there was anything else in the request besides the header if data.find('Content-Length') == -1: #request contains only header break - else: - #searching for that content-length field in the header - for line in data.split('\r\n'): - if line.find('Content-Length') != -1: - line = line.strip() - remaining = int(line.split(':')[1].strip()) - len(data) - + else: + #searching for that content-length field in the header + for line in data.split('\r\n'): + if line.find('Content-Length') != -1: + line = line.strip() + remaining = int(line.split(':')[1].strip()) - len(data) + if remaining <= 0: + break if data == "": break #now the data variable has the full request