[issue37301] CGIHTTPServer doesn't handle long POST requests
shajianrui
report at bugs.python.org
Wed Jun 19 01:22:40 EDT 2019
shajianrui <shajianrui at 126.com> added the comment:
@vsbogd,Thank you for your reply. But I find another problem.
I derive a subclass from sockerserver.StreamRequestHandler, and set the rbufsize to 0(As CGIHTTPRequestHandler do), like this demo below:
testserver.py:
import socketserver
class TestRequestHandler(socketserver.StreamRequestHandler):
rbufsize = 0 ###simulate CGIHTTPRequestHandler
def handle(self):
while True:
data = self.rfile.read(65536*1024) ###client should send 65536*1024 bytes.
print(len(data))
if len(data) == 0:
print("Connection closed.")
break
s = socketserver.TCPServer(("0.0.0.0", 8001), TestRequestHandler)
s.serve_forever()
testclient.py:
import socket
data = bytearray(65536*1024)
for i in range(65536*1024):
data[i] = 64 #Whatever you set.
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
c.connect(("127.0.0.1", 8001))
c.send(data)
The testserver.py can get the whole 65536*1024 data in every "data = self.rfile.read(65536*1024)" line. The normal output of testserver.py is:
testserver.py output:
67108864
0
Connection closed.
67108864
0
Connection closed.
In other words, this problem of "rfile.read(nbytes)" cannot be reproduce in this demo.
I dont know why, it seems this is not only the problem of the "rfile.read(nbytes)". I guess the CGIHTTPRequestHandler actually do something that make the "rfile.read(nbytes)" perform weirdly. However, I fail to find such a line in the code.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37301>
_______________________________________
More information about the Python-bugs-list
mailing list