Merge pull request #128 from vbanos/recordedurl-compile

Compile RecordedUrl regex to improve performance
This commit is contained in:
Noah Levitt 2019-05-06 15:52:28 -07:00 committed by GitHub
commit 50d29bdf80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -350,6 +350,7 @@ class WarcProxyHandler(warcprox.mitmproxy.MitmProxyHandler):
# logging better handled elsewhere?
pass
RE_MIMETYPE = re.compile(r'[;\s]')
class RecordedUrl:
logger = logging.getLogger("warcprox.warcproxy.RecordedUrl")
@ -389,7 +390,7 @@ class RecordedUrl:
self.mimetype = content_type
if self.mimetype:
# chop off subtype, and ensure there's no whitespace
self.mimetype = re.split(r'[;\s]', self.mimetype, 2)[0]
self.mimetype = RE_MIMETYPE.split(self.mimetype, 2)[0]
self.custom_type = custom_type
self.status = status