Skip to content

Commit

Permalink
FastHttpUser: Borrow requests encoding detection instead of using hom…
Browse files Browse the repository at this point in the history
…e-grown. Fixes #2415
  • Loading branch information
cyberw committed Oct 7, 2023
1 parent dfdd610 commit 5978f02
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
from geventhttpclient.response import HTTPConnectionClosed, HTTPSocketPoolResponse
from geventhttpclient.header import Headers

# borrow requests's content-type header parsing
from requests.utils import get_encoding_from_headers

from locust.user import User
from locust.exception import LocustError, CatchResponseError, ResponseError
from locust.env import Environment
Expand Down Expand Up @@ -460,7 +463,7 @@ def text(self) -> Optional[str]:
if self.headers is None:
self.encoding = "utf-8"
else:
self.encoding = self.headers.get("content-type", "").partition("charset=")[2] or "utf-8"
self.encoding = get_encoding_from_headers(self.headers)
return str(self.content, self.encoding, errors="replace")

@property
Expand Down

0 comments on commit 5978f02

Please sign in to comment.