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():