Skip to content

Commit

Permalink
Merge pull request #1194 from locustio/fix-encoding-detection-in-fast…
Browse files Browse the repository at this point in the history
…httplocust

Get encoding from content-type header instead of autodetecting using chardet (which is slow)
  • Loading branch information
cyberw authored Dec 17, 2019
2 parents 6ba31c8 + 16e49f3 commit 8348106
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import absolute_import

import chardet
import re
import six
import socket
Expand Down Expand Up @@ -252,9 +251,9 @@ def text(self):
Returns the text content of the response as a decoded string
(unicode on python2)
"""
# Decode unicode from detected encoding.
try:
content = unicode(self.content, self.apparent_encoding, errors='replace')
charset = self.headers.get('content-type', '').partition("charset=")[2]
content = unicode(self.content, charset or 'utf-8', errors='replace')
except (LookupError, TypeError):
# A LookupError is raised if the encoding was not found which could
# indicate a misspelling or similar mistake.
Expand All @@ -268,11 +267,6 @@ def text(self):
content = unicode(self.content, errors='replace')
return content

@property
def apparent_encoding(self):
"""The apparent encoding, provided by the chardet library."""
return chardet.detect(self.content)['encoding']

def raise_for_status(self):
"""Raise any connection errors that occured during the request"""
if hasattr(self, 'error') and self.error:
Expand Down

0 comments on commit 8348106

Please sign in to comment.