This commit is contained in:
Maximilian Hils 2016-12-13 14:03:00 +01:00
parent b39380b00f
commit e5b3c8bed3
5 changed files with 47 additions and 36 deletions

View File

@ -16,6 +16,7 @@ class Replace:
rex: a regular expression, as bytes. rex: a regular expression, as bytes.
s: the replacement string, as bytes s: the replacement string, as bytes
""" """
if "replacements" in updated:
lst = [] lst = []
for fpatt, rex, s in options.replacements: for fpatt, rex, s in options.replacements:
flt = flowfilter.parse(fpatt) flt = flowfilter.parse(fpatt)

View File

@ -8,6 +8,7 @@ class StickyAuth:
self.hosts = {} self.hosts = {}
def configure(self, options, updated): def configure(self, options, updated):
if "stickyauth" in updated:
if options.stickyauth: if options.stickyauth:
flt = flowfilter.parse(options.stickyauth) flt = flowfilter.parse(options.stickyauth)
if not flt: if not flt:
@ -15,8 +16,11 @@ class StickyAuth:
"stickyauth: invalid filter expression: %s" % options.stickyauth "stickyauth: invalid filter expression: %s" % options.stickyauth
) )
self.flt = flt self.flt = flt
else:
self.flt = None
def request(self, flow): def request(self, flow):
if self.flt:
host = flow.request.host host = flow.request.host
if "authorization" in flow.request.headers: if "authorization" in flow.request.headers:
self.hosts[host] = flow.request.headers["authorization"] self.hosts[host] = flow.request.headers["authorization"]

View File

@ -34,6 +34,7 @@ class StickyCookie:
self.flt = None self.flt = None
def configure(self, options, updated): def configure(self, options, updated):
if "stickycookie" in updated:
if options.stickycookie: if options.stickycookie:
flt = flowfilter.parse(options.stickycookie) flt = flowfilter.parse(options.stickycookie)
if not flt: if not flt:
@ -41,6 +42,8 @@ class StickyCookie:
"stickycookie: invalid filter expression: %s" % options.stickycookie "stickycookie: invalid filter expression: %s" % options.stickycookie
) )
self.flt = flt self.flt = flt
else:
self.flt = None
def response(self, flow): def response(self, flow):
if self.flt: if self.flt:

View File

@ -29,6 +29,8 @@ class StreamFile:
raise exceptions.OptionsError( raise exceptions.OptionsError(
"Invalid filter specification: %s" % options.filtstr "Invalid filter specification: %s" % options.filtstr
) )
else:
self.filt = None
if "streamfile" in updated: if "streamfile" in updated:
if self.stream: if self.stream:
self.done() self.done()

View File

@ -15,7 +15,8 @@ def test_configure():
def test_simple(): def test_simple():
r = stickyauth.StickyAuth() r = stickyauth.StickyAuth()
with taddons.context(): with taddons.context() as tctx:
tctx.configure(r, stickyauth=".*")
f = tflow.tflow(resp=True) f = tflow.tflow(resp=True)
f.request.headers["authorization"] = "foo" f.request.headers["authorization"] = "foo"
r.request(f) r.request(f)