summaryrefslogtreecommitdiffstats
path: root/Lib/wsgiref/simple_server.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-06-05 06:28:55 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-06-05 06:28:55 (GMT)
commited0425c60abe1b746b1ca5b4039984d2ad6583c4 (patch)
treedba5a8819bf4f6cf6ef4561b3b03cdb777794ddb /Lib/wsgiref/simple_server.py
parent889f914edb4253bdf4b475ed594199d67fcc08b7 (diff)
downloadcpython-ed0425c60abe1b746b1ca5b4039984d2ad6583c4.zip
cpython-ed0425c60abe1b746b1ca5b4039984d2ad6583c4.tar.gz
cpython-ed0425c60abe1b746b1ca5b4039984d2ad6583c4.tar.bz2
Issue #24291: Avoid WSGIRequestHandler doing partial writes
If the underlying send() method indicates a partial write, such as when the call is interrupted to handle a signal, the server would silently drop the remaining data. Also add deprecated support for SimpleHandler.stdout.write() doing partial writes.
Diffstat (limited to 'Lib/wsgiref/simple_server.py')
-rw-r--r--Lib/wsgiref/simple_server.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/wsgiref/simple_server.py b/Lib/wsgiref/simple_server.py
index e396788..7fddbe8 100644
--- a/Lib/wsgiref/simple_server.py
+++ b/Lib/wsgiref/simple_server.py
@@ -11,6 +11,7 @@ module. See also the BaseHTTPServer module docs for other API information.
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
+from io import BufferedWriter
import sys
import urllib.parse
from wsgiref.handlers import SimpleHandler
@@ -126,11 +127,17 @@ class WSGIRequestHandler(BaseHTTPRequestHandler):
if not self.parse_request(): # An error code has been sent, just exit
return
- handler = ServerHandler(
- self.rfile, self.wfile, self.get_stderr(), self.get_environ()
- )
- handler.request_handler = self # backpointer for logging
- handler.run(self.server.get_app())
+ # Avoid passing the raw file object wfile, which can do partial
+ # writes (Issue 24291)
+ stdout = BufferedWriter(self.wfile)
+ try:
+ handler = ServerHandler(
+ self.rfile, stdout, self.get_stderr(), self.get_environ()
+ )
+ handler.request_handler = self # backpointer for logging
+ handler.run(self.server.get_app())
+ finally:
+ stdout.detach()