Skip to content

Commit 7e2214c

Browse files
committed
fix byte streaming endpoint in python3
1 parent 16d6fea commit 7e2214c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

httpbin/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def generate_bytes():
481481
chunks = []
482482

483483
for i in xrange(n):
484-
chunks.append(chr(random.randint(0, 255)))
484+
chunks.append(os.urandom(1))
485485
if len(chunks) == chunk_size:
486486
yield(bytes().join(chunks))
487487
chunks = []

test_httpbin.py

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ def test_get_bytes(self):
134134
self.assertEqual(len(response.get_data()), 1024)
135135
self.assertEqual(response.status_code, 200)
136136

137+
def test_stream_bytes(self):
138+
response = self.app.get('/stream-bytes/1024')
139+
self.assertEqual(len(response.get_data()), 1024)
140+
self.assertEqual(response.status_code, 200)
141+
137142

138143
if __name__ == '__main__':
139144
unittest.main()

0 commit comments

Comments
 (0)