From 03013e3227dd82f53471efe611759a8929bf58a3 Mon Sep 17 00:00:00 2001 From: Wutiphong Date: Sat, 20 Apr 2019 20:54:45 +0700 Subject: [PATCH] Add random delay --- httpbin/core.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/httpbin/core.py b/httpbin/core.py index a82c1b88..8dc511b3 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -1220,6 +1220,31 @@ def delay_response(delay): get_dict("url", "args", "form", "data", "origin", "headers", "files") ) +@app.route("/random-delay/", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "TRACE"]) +def random_delay_response(delay): + """Returns a random delayed response (max of 10 seconds). + --- + tags: + - Dynamic data + parameters: + - in: path + name: delay + type: float + produces: + - application/json + responses: + 200: + description: A delayed response. + """ + random.seed(None) + delay = random.random() * min(float(delay), 10.0) + + time.sleep(delay) + + return jsonify( + get_dict("url", "args", "form", "data", "origin", "headers", "files") + ) + @app.route("/drip") def drip():