httpserver.py: Pass Content-Length to read call

If a POST request is sent to the built-in http server the handling function does
not terminate because the rfile.read() function blocks.

This patch passes the Content-Length value to the self.rfile.read() function
that is required for it to do not block the method.

Regarding RFC 2616
(http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4) the
Content-Length header is expected to be sent otherwise this patch assumes a zero
length.
This commit is contained in:
Moritz Lipp 2015-08-17 21:46:33 +02:00
parent 7d7945e719
commit 52bebde9df
1 changed files with 2 additions and 1 deletions

View File

@ -246,7 +246,8 @@ class SupyHTTPRequestHandler(BaseHTTPRequestHandler):
'CONTENT_TYPE':self.headers['Content-Type'],
})
else:
form = self.rfile.read()
content_length = int(self.headers.get('Content-Length', '0'))
form = self.rfile.read(content_length)
self.do_X('doPost', form=form)
def do_HEAD(self):