From bbb3965826c91406b94b819af7315ea1d39ec217 Mon Sep 17 00:00:00 2001
From: Nicolas Restrepo <nrestrepo.r05@gmail.com>
Date: Thu, 17 Jun 2021 07:04:04 -0400
Subject: [PATCH] Refs #24121 -- Added __repr__() to StreamingHttpResponse and
 subclasses.

---
 django/http/response.py              | 7 +++++++
 tests/httpwrappers/tests.py          | 7 +++++++
 tests/responses/test_fileresponse.py | 7 +++++++
 3 files changed, 21 insertions(+)

diff --git a/django/http/response.py b/django/http/response.py
index 99f0020335..901501dad1 100644
--- a/django/http/response.py
+++ b/django/http/response.py
@@ -402,6 +402,13 @@ class StreamingHttpResponse(HttpResponseBase):
         # See the `streaming_content` property methods.
         self.streaming_content = streaming_content
 
+    def __repr__(self):
+        return '<%(cls)s status_code=%(status_code)d%(content_type)s>' % {
+            'cls': self.__class__.__qualname__,
+            'status_code': self.status_code,
+            'content_type': self._content_type_for_repr,
+        }
+
     @property
     def content(self):
         raise AttributeError(
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py
index 728e879b5c..a04555b6cd 100644
--- a/tests/httpwrappers/tests.py
+++ b/tests/httpwrappers/tests.py
@@ -663,6 +663,13 @@ class StreamingHttpResponseTests(SimpleTestCase):
         r = StreamingHttpResponse(iter(['hello', 'world']))
         self.assertEqual(r.getvalue(), b'helloworld')
 
+    def test_repr(self):
+        r = StreamingHttpResponse(iter(['hello', 'café']))
+        self.assertEqual(
+            repr(r),
+            '<StreamingHttpResponse status_code=200, "text/html; charset=utf-8">',
+        )
+
 
 class FileCloseTests(SimpleTestCase):
 
diff --git a/tests/responses/test_fileresponse.py b/tests/responses/test_fileresponse.py
index 46d407bdf5..9e33df010e 100644
--- a/tests/responses/test_fileresponse.py
+++ b/tests/responses/test_fileresponse.py
@@ -89,3 +89,10 @@ class FileResponseTests(SimpleTestCase):
             response.headers['Content-Disposition'],
             "attachment; filename*=utf-8''%E7%A5%9D%E6%82%A8%E5%B9%B3%E5%AE%89.odt"
         )
+
+    def test_repr(self):
+        response = FileResponse(io.BytesIO(b'binary content'))
+        self.assertEqual(
+            repr(response),
+            '<FileResponse status_code=200, "application/octet-stream">',
+        )