Skip to content

Commit 76575c9

Browse files
authored
Merge pull request #2642 from locustio/fix-issue-with-fasthttpuser-with-stream-true-and-connection-error
Dont throw an exception in FastHttpUser if a request is made with stream=True and the connection fails
2 parents c69316d + 63bfdc7 commit 76575c9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Diff for: locust/contrib/fasthttp.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,18 @@ def request(
230230
if not allow_redirects:
231231
self.client.redirect_resonse_codes = old_redirect_response_codes
232232

233+
request_meta["response_length"] = 0 # default value, if length cannot be determined
234+
233235
# get the length of the content, but if the argument stream is set to True, we take
234236
# the size from the content-length header, in order to not trigger fetching of the body
235237
if stream:
236-
request_meta["response_length"] = int(response.headers.get("response_length") or 0)
238+
if response.headers and "response_length" in response.headers:
239+
request_meta["response_length"] = int(response.headers["response_length"])
237240
else:
238241
try:
239-
request_meta["response_length"] = len(response.content or "")
242+
request_meta["response_length"] = len(response.content) if response.content else 0
240243
except HTTPParseError as e:
241244
request_meta["response_time"] = (time.perf_counter() - start_perf_counter) * 1000
242-
request_meta["response_length"] = 0
243245
request_meta["exception"] = e
244246
self.environment.events.request.fire(**request_meta)
245247
return response

0 commit comments

Comments
 (0)