Skip to content

Dont throw an exception in FastHttpUser if a request is made with stream=True and the connection fails #2642

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

Merged
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
8 changes: 5 additions & 3 deletions locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,18 @@ def request(
if not allow_redirects:
self.client.redirect_resonse_codes = old_redirect_response_codes

request_meta["response_length"] = 0 # default value, if length cannot be determined

# get the length of the content, but if the argument stream is set to True, we take
# the size from the content-length header, in order to not trigger fetching of the body
if stream:
request_meta["response_length"] = int(response.headers.get("response_length") or 0)
if response.headers and "response_length" in response.headers:
request_meta["response_length"] = int(response.headers["response_length"])
else:
try:
request_meta["response_length"] = len(response.content or "")
request_meta["response_length"] = len(response.content) if response.content else 0
except HTTPParseError as e:
request_meta["response_time"] = (time.perf_counter() - start_perf_counter) * 1000
request_meta["response_length"] = 0
request_meta["exception"] = e
self.environment.events.request.fire(**request_meta)
return response
Expand Down
Loading