Skip to content

Pass req to context enrichers #114

@LukasHeimann

Description

@LukasHeimann

Describe the feature request

#87 introduced the notion of ContextEnrichers, which take the context of feature toggle evaluation modify it in some meaningful way. The use case of #87 is built around using fields that are already part of the context from the start.

To support more use cases, it would be helpful to pass the full request to context enrichers, so further custom information can be pulled from it into the context.

Background

Taking only fields from the existing context to enrich it is really limiting. This is especially true if you run the unleash-proxy embedded in a node application that already preprocesses the request a bit. Imagine running an application with authentication and having session information at hand (at req.user).

You would want to provide the user information as part of the context to use it in strategies. Without having access to the request, this is not possible. A workaround could only be knowing which requests unleash-proxy handles and how the context is transferred in each of them (req.query, req.body), and adding the fields there via a custom middleware, completely sidestepping the context enrichers in an honestly rather fragile way.

Solution suggestions

Enhance the ContextEnrichter interface to consume a Request. Pass the current req to the enrichContext function, so it can provide it to the context enricher chain.

This depends partly on #109, which makes sure enrichContext is actually called consistently across use endpoints

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    For later

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions