Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Proxy Friendly Setting #636

Closed

Conversation

zachcoleman
Copy link
Contributor

Related Issue(s):

Description:

Create a setting to help make it more proxy friendly.

PR Checklist:

  • pre-commit hooks pass locally
  • Tests pass (run make test)
  • Documentation has been updated to reflect changes, if applicable, and docs build successfully (run make docs)
  • Changes are added to the CHANGELOG.

@zachcoleman
Copy link
Contributor Author

I want to be clear that while I think the proxy middleware works, the experience I had was that scheme is not well persisted and that a proxy accepting https forwarding them as http was not being reflected in the links dynamically configured based on base_url.

@vincentsarago vincentsarago requested a review from jonhealy1 April 9, 2024 16:56
@vincentsarago
Copy link
Member

going back to the issue

The base URL in links is built using the Starlette Request base_url property. But this value can be misleading, especially when the app is used behind a proxy.

I find this a bit questionable because it's usually a configuration issue. In the different project I managed we've been careful not to add any hack around base_url and request's url construction (developmentseed/titiler#342) 🤔

@zachcoleman
Copy link
Contributor Author

going back to the issue

The base URL in links is built using the Starlette Request base_url property. But this value can be misleading, especially when the app is used behind a proxy.

I find this a bit questionable because it's usually a configuration issue. In the different project I managed we've been careful not to add any hack around base_url and request's url construction (developmentseed/titiler#342) 🤔

I 100% agree this is a hack and will close.

I do want to point out that this is an issue where the scheme http is swapped in for https. We have this currently in as a middleware instead of this hack. Using:

class ForwardedSchemeMiddleware(BaseHTTPMiddleware):
    async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response:
        scheme = request.headers.get("x-forwarded-proto")
        if scheme:
            request.scope["scheme"] = scheme
        response = await call_next(request)
        return response

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants