[issue37301] CGIHTTPServer doesn't handle long POST requests
shajianrui
report at bugs.python.org
Sat Jun 22 15:53:17 EDT 2019
shajianrui <shajianrui at 126.com> added the comment:
Sorry for replying so late, and thank you very much for your reply and explanation.
At first reply to you last post: I think at least in the non-unix environment, the CGIHTTPRequestHandler read the whole(expected) data from rfile and then transfer it to the CGI script.
And considering the code for Unix environment, I dont think to set the rbufsize to -1 is a good idea. I prefer a safer way: to do a read() loop and read until nbytes received. It is much slower but more compatible. Like this:
if self.command.lower() == "post" and nbytes > 0:
#data = self.rfile.read(nbytes) #Original code at line 1199
databuf = bytearray(nbytes)
datacount = 0
while datacount + 1 < nbytes:
buf = self.rfile.read(self.request.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)) #You can set your number.
if len(buf) == 0:
print("Connection closed before nbytes reached.")
break
for i in range(len(buf)):
databuf[datacount] = buf[i]
datacount += 1
if datacount == nbytes:
break
data = bytes(databuf)
This code is only for explanation... Not for use...
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37301>
_______________________________________
More information about the Python-bugs-list
mailing list