def request(context, flow): flow.mastermind = {"rule": None} print(flow.request.url) if driver.name: ruleset = rules.load(driver.name, context.source_dir) filtered_rules = rules.select(flow.request.method, flow.request.url, ruleset) rule = rules.head(filtered_rules) if len(filtered_rules) > 1: context.log("Too many rules: {}".format(map(rules.url, filtered_rules))) if rule: flow.mastermind['rule'] = rule context.log("Intercepted URL: {}".format(rules.url(rule))) if rules.skip(rule): return flow.reply(http.response(204)) rules.process_headers('request', rule, flow.request.headers)
def request(context, flow): flow.mastermind = {"rule": None} print(flow.request.url) if driver.name: ruleset = rules.load(driver.name, context.source_dir) filtered_rules = rules.select(flow.request.method, flow.request.url, ruleset) rule = rules.head(filtered_rules) if len(filtered_rules) > 1: context.log("Too many rules: {}".format( map(rules.url, filtered_rules))) if rule: flow.mastermind['rule'] = rule context.log("Intercepted URL: {}".format(rules.url(rule))) if rules.skip(rule): return flow.reply(http.response(204)) rules.process_headers('request', rule, flow.request.headers)
def test_skip_false(): assert r.skip({'request': {'skip': False}}) is False assert r.skip({'request': {}}) is False assert r.skip({}) is False
def test_skip_true(): assert r.skip(rule) is True
def test_skip_false(): assert r.skip({'request': {'skip': False}}) == False assert r.skip({'request': {}}) == False assert r.skip({}) == False
def test_skip_true(): assert r.skip(rule) == True