Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add random delay #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions httpbin/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,31 @@ def delay_response(delay):
get_dict("url", "args", "form", "data", "origin", "headers", "files")
)

@app.route("/random-delay/<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():
Expand Down