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

Host header handling is inconsistent when using the <loopback> #1604

Open
aryszka opened this issue Nov 13, 2020 · 3 comments
Open

Host header handling is inconsistent when using the <loopback> #1604

aryszka opened this issue Nov 13, 2020 · 3 comments

Comments

@aryszka
Copy link
Contributor

aryszka commented Nov 13, 2020

This set of routes should return "It works!":

main: * -> logHeader() -> setRequestHeader("Host", "www.example.org") -> <loopback>;
org:  Host("www.example.org") -> inlineContent("It works!") -> <shunt>;

But it ends up in an infinite loop. This, however, works as expected:

main: * -> logHeader() -> setRequestHeader("Host", "www.example.org") -> <loopback>;
org:  Header("Host", "www.example.org") -> inlineContent("It works!") -> <shunt>;

where the only change is using the Header("Host", "...") predicate instead of Host("..."). Both approaches should work the same way.

@szuecs
Copy link
Member

szuecs commented Nov 13, 2020

I think setRequestHeader sets it into the http.Header map and Host() works on request.Host which is not request.Header["Host"]
So it's not really <loopback> problem but a general one that we might want to fix

@AlexanderYastrebov
Copy link
Member

@szuecs

So it's not really problem but a general one that we might want to fix

There are three things to consider request.Host used by Host predicate, Host header and context.OutgoingHost() used for backend request construction.

@szuecs
Copy link
Member

szuecs commented Nov 14, 2020

req.Header.Get(„Host“) is always empty string in a http handler or you added it yourself. We don’t copy request.Host to the req.Header.

The Host() predicate works on req.Host, setRequestHeader works only on req.Header. So the why is clear, but we might want to change the predicate to also check the Header or I think better would be to change the filter in case of Host we set req.Host.
Of course req.OutgoingHost needs to be considered depending if it’s set or not.

I think @aryszka can clarify how the details of the change should be.

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

No branches or pull requests

3 participants