-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
bpo-8077 Fix CGI Handling of POST on Windows. #25652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1192,20 +1192,42 @@ def run_cgi(self): | |
| nbytes = int(length) | ||
| except (TypeError, ValueError): | ||
| nbytes = 0 | ||
|
|
||
| data = None | ||
| rfile = None | ||
|
|
||
| if self.command.lower() == "post" and nbytes > 0: | ||
| data = self.rfile.read(nbytes) | ||
| if len(data) < nbytes: | ||
| import tempfile | ||
| rfile = tempfile.TemporaryFile("wb+") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than an actual file, could we use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. All we care about is reading from socket and temporarily storing to a different file like object (which can support large files). I will try with BytesIO. |
||
| rfile.write(data) | ||
| bufsize = 2 << 16 | ||
| while True: | ||
| buf = self.rfile.read(bufsize) | ||
| if not buf: | ||
| break | ||
| rfile.write(buf) | ||
| if rfile.tell() == nbytes: | ||
| break | ||
| rfile.seek(0) | ||
| data = None | ||
|
|
||
| # throw away additional data [see bug #427345] | ||
| while select.select([self.rfile._sock], [], [], 0)[0]: | ||
| if not self.rfile._sock.recv(1): | ||
| break | ||
|
|
||
| stdin = subprocess.PIPE | ||
| if rfile is not None: | ||
| stdin = rfile | ||
| p = subprocess.Popen(cmdline, | ||
| stdin=subprocess.PIPE, | ||
| stdin=stdin, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| env = env | ||
| ) | ||
| if self.command.lower() == "post" and nbytes > 0: | ||
| data = self.rfile.read(nbytes) | ||
| else: | ||
| data = None | ||
| # throw away additional data [see bug #427345] | ||
| while select.select([self.rfile._sock], [], [], 0)[0]: | ||
| if not self.rfile._sock.recv(1): | ||
| break | ||
|
|
||
| stdout, stderr = p.communicate(data) | ||
| self.wfile.write(stdout) | ||
| if stderr: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have windows, so I didn't test even the existing code in Windows. I believe that even the existing code is not going to work on windows due the condition nbytes > 0
nbytes is from
Content-Lengthand I see that https://bugs.python.org/issue24764 Content-Length for multi-part form data was removed.When I tried to add test, I could not exercise this.