Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add reverse proxy mode #65

Open
mithrandi opened this issue May 31, 2017 · 1 comment
Open

Add reverse proxy mode #65

mithrandi opened this issue May 31, 2017 · 1 comment

Comments

@mithrandi
Copy link
Contributor

mithrandi commented May 31, 2017

This probably shouldn't be active all the time, but it would be something to activate when running behind a reverse proxy, in order to set the request protocol / host / port correctly based on X-Forwarded-Proto and Host so that URL generation happens correctly.

We could have a flag on SiteConfiguration that activates this, along with code in the site that calls setHost based on the incoming request headers.

@mithrandi
Copy link
Contributor Author

PoC that I'm monkey-patching in at the moment:

    def process(self, *a, **kw):
        """
        Override the host if we get proxy info.
        """
        proto = self.requestHeaders.getRawHeaders(b'x-forwarded-proto')
        if proto is not None:
            proto = proto[0]
            parts = (
                self.requestHeaders.getRawHeaders(b'host')[0]
                .split(b':', 1))
            host = parts[0]
            if len(parts) == 1:
                port = 443 if proto == b'https' else 80
            else:
                port = int(parts[1])
            self.setHost(host, port, ssl=proto == b'https')
        return self.store.transact(NevowRequest.process, self, *a, **kw)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant