Example #1
0
    def _process(self, flow: HTTPFlow, phase: Phase,
                 content: bytes) -> Tuple[str, dict]:
        route, route_filters = match_route(
            proxy_mode=ctx.get_proxy_context().mode,
            phase=phase,
            flow=flow,
        )
        if not route_filters:
            return content, None

        with ctx.use_context(ctx.FlowContext(
                flow=flow,
                phase=phase)), ctx.use_context(ctx.RouteContext(route=route)):
            # TODO: Encapsulate flow transformation somewere else
            content, ops_applications = transform_body(route_filters, content)
            matched_filters = [{
                'id': rule.id,
                'operation_applied': op_applied
            } for rule, op_applied in zip(route_filters, ops_applications)]
            return content, {'route_id': route.id, 'filters': matched_filters}
Example #2
0
def flow_context():
    return ctx.FlowContext(
        flow=Mock(id='313980a8-ff6c-4b13-b5a3-03909389295b'),
        phase=Phase.REQUEST,
    )