From 5021b420ef2aa5319a5c23557744bb5507785f91 Mon Sep 17 00:00:00 2001 From: Peter Burns Date: Thu, 18 Sep 2014 16:03:19 -0700 Subject: [PATCH] Send an explicit Content-Length header with /drip/ It's useful for testing tools which track the progress of a request to know the content length ahead of time. Test included. I've verified that the new tests do fail without this change, response.content_length is None if an explicit Content-Length isn't set. --- httpbin/core.py | 1 + test_httpbin.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/httpbin/core.py b/httpbin/core.py index 2e8774b..1cc9c9c 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -419,6 +419,7 @@ def drip(): response = Response(generate_bytes(), headers={ "Content-Type": "application/octet-stream", + "Content-Length": str(numbytes), }) response.status_code = code diff --git a/test_httpbin.py b/test_httpbin.py index 8af40d8..b19e999 100755 --- a/test_httpbin.py +++ b/test_httpbin.py @@ -177,11 +177,13 @@ class HttpbinTestCase(unittest.TestCase): def test_drip(self): response = self.app.get('/drip?numbytes=400&duration=2&delay=1') + self.assertEqual(response.content_length, 400) self.assertEqual(len(response.get_data()), 400) self.assertEqual(response.status_code, 200) def test_drip_with_custom_code(self): response = self.app.get('/drip?numbytes=400&duration=2&code=500') + self.assertEqual(response.content_length, 400) self.assertEqual(len(response.get_data()), 400) self.assertEqual(response.status_code, 500)