diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py
index 02957c51a2..d0a74f2c7b 100644
--- a/django/core/servers/basehttp.py
+++ b/django/core/servers/basehttp.py
@@ -7,6 +7,7 @@ This is a simple server for use in testing or debugging Django apps. It hasn't
 been reviewed for security issues. DON'T USE IT FOR PRODUCTION USE!
 """
 
+from http import HTTPStatus
 import logging
 import socket
 import socketserver
@@ -94,15 +95,45 @@ class ServerHandler(simple_server.ServerHandler):
             content_length = 0
         super().__init__(LimitedStream(stdin, content_length), stdout, stderr, environ, **kwargs)
 
+    def _write(self, data):
+        if self.headers_sent and self.headers.get('Transfer-Encoding', False) == "chunked":
+            data = format(len(data), "X").encode() + b"\r\n" + data + b"\r\n"
+
+        super()._write(data)
+
+    def send_headers(self):
+        """Transmit headers to the client, via self._write()"""
+        self.cleanup_headers()
+        if not self.origin_server or self.client_is_modern():
+            self.send_preamble()
+            self._write(bytes(self.headers))
+        # Only mark headers as sent after they're actually written
+        self.headers_sent = True
+
+    def finish_content(self):
+        super().finish_content()
+
+        if self.headers_sent and self.headers.get('Transfer-Encoding', False) == "chunked":
+            self._write(b'')  # End message for chunked encoding
+
+    def set_content_length(self):
+        """Compute Content-Length or switch to chunked encoding if possible"""
+        try:
+            blocks = len(self.result)
+        except (TypeError, AttributeError, NotImplementedError):
+            pass
+        else:
+            if blocks == 1:
+                self.headers['Content-Length'] = str(self.bytes_sent)
+                return
+
+        # Switch to chunked encoding
+        self.headers['Transfer-Encoding'] = 'chunked'
+
     def cleanup_headers(self):
         super().cleanup_headers()
-        # HTTP/1.1 requires support for persistent connections. Send 'close' if
-        # the content length is unknown to prevent clients from reusing the
-        # connection.
-        if 'Content-Length' not in self.headers:
-            self.headers['Connection'] = 'close'
         # Persistent connections require threading server.
-        elif not isinstance(self.request_handler.server, socketserver.ThreadingMixIn):
+        if not isinstance(self.request_handler.server, socketserver.ThreadingMixIn):
             self.headers['Connection'] = 'close'
         # Mark the connection for closing if it's set as such above or if the
         # application sent the header.
@@ -172,19 +203,34 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler):
         self.handle_one_request()
         while not self.close_connection:
             self.handle_one_request()
+
+        # Wait for the connection to be closed by the client to ensure
+        # that all data was received. Shutting down the connection seems
+        # to flush any data in the send buffer and immediately ends the
+        # connection, which risks having large responses cut off.
+        if getattr(self, 'request_version', None) == 'HTTP/1.1':
+            self.rfile.peek()
+
         try:
             self.connection.shutdown(socket.SHUT_WR)
         except (AttributeError, OSError):
             pass
 
     def handle_one_request(self):
-        """Copy of WSGIRequestHandler.handle() but with different ServerHandler"""
+        """
+        Copy of WSGIRequestHandler.handle() but with different ServerHandler,
+        and re-aligned with BaseHTTPRequestHandler.handle()
+        """
         self.raw_requestline = self.rfile.readline(65537)
         if len(self.raw_requestline) > 65536:
             self.requestline = ''
             self.request_version = ''
             self.command = ''
-            self.send_error(414)
+            self.send_error(HTTPStatus.REQUEST_URI_TOO_LONG)
+            return
+
+        if not self.raw_requestline:
+            self.close_connection = True
             return
 
         if not self.parse_request():  # An error code has been sent, just exit
@@ -196,6 +242,8 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler):
         handler.request_handler = self      # backpointer for logging & connection closing
         handler.run(self.server.get_app())
 
+        self.wfile.flush() #actually send the response if not already done.
+
 
 def run(addr, port, wsgi_handler, ipv6=False, threading=False, server_cls=WSGIServer):
     server_address = (addr, port)
diff --git a/tests/servers/test_basehttp.py b/tests/servers/test_basehttp.py
index 32fdbf3c0e..4bedc390dc 100644
--- a/tests/servers/test_basehttp.py
+++ b/tests/servers/test_basehttp.py
@@ -1,4 +1,4 @@
-from io import BytesIO
+from io import BytesIO, BufferedReader
 
 from django.core.handlers.wsgi import WSGIRequest
 from django.core.servers.basehttp import WSGIRequestHandler
@@ -19,7 +19,7 @@ class WSGIRequestHandlerTestCase(SimpleTestCase):
 
     def test_log_message(self):
         request = WSGIRequest(self.request_factory.get('/').environ)
-        request.makefile = lambda *args, **kwargs: BytesIO()
+        request.makefile = lambda *args, **kwargs: BufferedReader(BytesIO())
         handler = WSGIRequestHandler(request, '192.168.0.2', None)
         level_status_codes = {
             'info': [200, 301, 304],
@@ -41,7 +41,7 @@ class WSGIRequestHandlerTestCase(SimpleTestCase):
 
     def test_https(self):
         request = WSGIRequest(self.request_factory.get('/').environ)
-        request.makefile = lambda *args, **kwargs: BytesIO()
+        request.makefile = lambda *args, **kwargs: BufferedReader(BytesIO())
 
         handler = WSGIRequestHandler(request, '192.168.0.2', None)
 
@@ -75,6 +75,7 @@ class WSGIRequestHandlerTestCase(SimpleTestCase):
         rfile.write(b"Some_Header: bad\r\n")
         rfile.write(b"Other_Header: bad\r\n")
         rfile.seek(0)
+        rfile = BufferedReader(rfile)
 
         # WSGIRequestHandler closes the output file; we need to make this a
         # no-op so we can still read its contents.
diff --git a/tests/servers/tests.py b/tests/servers/tests.py
index 33d0605443..d239d34a49 100644
--- a/tests/servers/tests.py
+++ b/tests/servers/tests.py
@@ -69,32 +69,23 @@ class LiveServerViews(LiveServerBase):
 
     def test_closes_connection_without_content_length(self):
         """
-        A HTTP 1.1 server is supposed to support keep-alive. Since our
-        development server is rather simple we support it only in cases where
-        we can detect a content length from the response. This should be doable
-        for all simple views and streaming responses where an iterable with
-        length of one is passed. The latter follows as result of `set_content_length`
-        from https://github.com/python/cpython/blob/master/Lib/wsgiref/handlers.py.
-
-        If we cannot detect a content length we explicitly set the `Connection`
-        header to `close` to notify the client that we do not actually support
-        it.
+        TODO - Updated description
         """
         conn = HTTPConnection(LiveServerViews.server_thread.host, LiveServerViews.server_thread.port, timeout=1)
         try:
             conn.request('GET', '/streaming_example_view/', headers={'Connection': 'keep-alive'})
             response = conn.getresponse()
-            self.assertTrue(response.will_close)
+            self.assertFalse(response.will_close)
             self.assertEqual(response.read(), b'Iamastream')
             self.assertEqual(response.status, 200)
-            self.assertEqual(response.getheader('Connection'), 'close')
+            self.assertIsNone(response.getheader('Connection'))
 
             conn.request('GET', '/streaming_example_view/', headers={'Connection': 'close'})
             response = conn.getresponse()
-            self.assertTrue(response.will_close)
+            self.assertFalse(response.will_close)
             self.assertEqual(response.read(), b'Iamastream')
             self.assertEqual(response.status, 200)
-            self.assertEqual(response.getheader('Connection'), 'close')
+            self.assertIsNone(response.getheader('Connection'))
         finally:
             conn.close()
 
