Skip to content

Commit

Permalink
Fixed response failure for unsupported encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Dec 12, 2023
1 parent 247fee9 commit 8903783
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def rest(
with self.client.request(method, url, catch_response=True, headers=headers, **kwargs) as r:
resp = cast(RestResponseContextManager, r)
resp.js = None # type: ignore
if resp.text is None:
if resp.content is None:
resp.failure(str(resp.error))
elif resp.text:
try:
Expand Down Expand Up @@ -461,14 +461,16 @@ def text(self) -> Optional[str]:
if self.encoding is None:
if self.headers is None:
# No information, try to detect
self.encoding = str(detect(self.content)["encoding"])
self.encoding = detect(self.content)["encoding"]
else:
self.encoding = get_encoding_from_headers(self.headers)
# No information, try to detect
if not self.encoding:
self.encoding = str(detect(self.content)["encoding"])

return str(self.content, self.encoding, errors="replace")
self.encoding = detect(self.content)["encoding"]
if self.encoding is None:
return None
return str(self.content, str(self.encoding), errors="replace")


@property
def url(self) -> Optional[str]:
Expand Down

0 comments on commit 8903783

Please sign in to comment.