Skip to content

Using urljoin wth an absolute path in the OFREPProvider prevents connection to self-hosted APIs with OFREP API not at base / path #141

@atmask

Description

@atmask

Description: Operations teams often host feature flagging services themselves rather than using a SaaS solution. In this instance they put their api under a path other than the base / path. The expected behaviour when using the OFREP Provider would be that I pass my base_url (i.e. https://mydomain.com/tools/featureflags) and all subsequent requests would be made using the defined base_url.

The actual behaviour is that the urljoin("https://mydomain.com/tools/featureflags", f"/ofrep/v1/evaluate/flags/{flag_key}") strips the path from the base_url and produces a request to https://mydomain.com/ofrep/v1/evaluate/flags/{flag_key}. This is because the second param in urljoin is being passed as an absolute path that starts with "/"

Proposed Solution: Convert the second arg of urljoin to a relative path and add logic to ensure that the first args ends with /

            evaluation_base_url = self.base_url if self.base_url.endswith("/") else f"{self.base_url}/"
            response = self.session.post(
                urljoin(evaluation_base_url, f"ofrep/v1/evaluate/flags/{flag_key}"),
                json=_build_request_data(evaluation_context),
                timeout=self.timeout,
                headers=self.headers_factory() if self.headers_factory else None,
            )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions