diff --git a/httpbin/core.py b/httpbin/core.py index c8b5e20..9b81d68 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -481,7 +481,7 @@ def stream_random_bytes(n): chunks = [] for i in xrange(n): - chunks.append(chr(random.randint(0, 255))) + chunks.append(os.urandom(1)) if len(chunks) == chunk_size: yield(bytes().join(chunks)) chunks = [] diff --git a/test_httpbin.py b/test_httpbin.py index eabd9c4..624b64b 100755 --- a/test_httpbin.py +++ b/test_httpbin.py @@ -134,6 +134,11 @@ class HttpbinTestCase(unittest.TestCase): self.assertEqual(len(response.get_data()), 1024) self.assertEqual(response.status_code, 200) + def test_stream_bytes(self): + response = self.app.get('/stream-bytes/1024') + self.assertEqual(len(response.get_data()), 1024) + self.assertEqual(response.status_code, 200) + if __name__ == '__main__': unittest.main()