mirror of
https://github.com/django/django.git
synced 2025-10-30 17:16:10 +00:00
Fixed #18523 -- Added stream-like API to HttpResponse.
Added getvalue() to HttpResponse to return the content of the response, along with a few other methods to partially match io.IOBase. Thanks Claude Paroz for the suggestion and Nick Sanford for review.
This commit is contained in:
committed by
Tim Graham
parent
f7969b0920
commit
ebc8e79cf3
@@ -407,6 +407,15 @@ class HttpResponseTests(unittest.TestCase):
|
||||
r.write(b'def')
|
||||
self.assertEqual(r.content, b'abcdef')
|
||||
|
||||
def test_stream_interface(self):
|
||||
r = HttpResponse('asdf')
|
||||
self.assertEqual(r.getvalue(), b'asdf')
|
||||
|
||||
r = HttpResponse()
|
||||
self.assertEqual(r.writable(), True)
|
||||
r.writelines(['foo\n', 'bar\n', 'baz\n'])
|
||||
self.assertEqual(r.content, b'foo\nbar\nbaz\n')
|
||||
|
||||
def test_unsafe_redirect(self):
|
||||
bad_urls = [
|
||||
'data:text/html,<script>window.alert("xss")</script>',
|
||||
@@ -537,6 +546,9 @@ class StreamingHttpResponseTests(TestCase):
|
||||
with self.assertRaises(Exception):
|
||||
r.tell()
|
||||
|
||||
r = StreamingHttpResponse(iter(['hello', 'world']))
|
||||
self.assertEqual(r.getvalue(), b'helloworld')
|
||||
|
||||
|
||||
class FileCloseTests(TestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user