mirror of
https://github.com/kennethreitz/httpbin.git
synced 2026-06-05 23:00:18 +00:00
drip endpoint: adding custom status support
This commit is contained in:
@@ -29,7 +29,7 @@ Freely hosted in [HTTP](http://httpbin.org), [HTTPS](https://httpbin.org) & [EU]
|
||||
- [`/digest-auth/:qop/:user/:passwd`](http://httpbin.org/digest-auth/auth/user/passwd) Challenges HTTP Digest Auth.
|
||||
- [`/stream/:n`](http://httpbin.org/stream/20) Streams *n*–100 lines.
|
||||
- [`/delay/:n`](http://httpbin.org/delay/3) Delays responding for *n*–10 seconds.
|
||||
- [`/drip?numbytes=n&duration=s&delay=s`](http://httpbin.org/drip?numbytes=5&duration=5) Drips data over a duration after an optional initial delay.
|
||||
- [`/drip?numbytes=n&duration=s&delay=s&code=code`](http://httpbin.org/drip?numbytes=5&duration=5&code=200) Drips data over a duration after an optional initial delay, then (optionally) returns with the given status code.
|
||||
- [`/html`](http://httpbin.org/html) Renders an HTML Page.
|
||||
- [`/robots.txt`](http://httpbin.org/robots.txt) Returns some robots.txt rules.
|
||||
- [`/deny`](http://httpbin.org/deny) Denied by robots.txt file.
|
||||
|
||||
+7
-2
@@ -405,6 +405,7 @@ def drip():
|
||||
args = CaseInsensitiveDict(request.args.items())
|
||||
duration = float(args.get('duration', 2))
|
||||
numbytes = int(args.get('numbytes', 10))
|
||||
code = int(args.get('code', 200))
|
||||
pause = duration / numbytes
|
||||
|
||||
delay = float(args.get('delay', 0))
|
||||
@@ -416,9 +417,13 @@ def drip():
|
||||
yield u"*".encode('utf-8')
|
||||
time.sleep(pause)
|
||||
|
||||
return Response(generate_bytes(), headers={
|
||||
response = Response(generate_bytes(), headers={
|
||||
"Content-Type": "application/octet-stream",
|
||||
})
|
||||
})
|
||||
|
||||
response.status_code = code
|
||||
|
||||
return response
|
||||
|
||||
@app.route('/base64/<value>')
|
||||
def decode_base64(value):
|
||||
|
||||
@@ -180,6 +180,11 @@ class HttpbinTestCase(unittest.TestCase):
|
||||
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(len(response.get_data()), 400)
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
def test_get_bytes(self):
|
||||
response = self.app.get('/bytes/1024')
|
||||
self.assertEqual(len(response.get_data()), 1024)
|
||||
|
||||
Reference in New Issue
Block a user