Compile RecordedUrl regex to improve performance

Minor optimisation.
This commit is contained in:
Vangelis Banos 2019-05-02 07:11:24 +00:00
parent 38d6e4337d
commit be7048844b

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