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

Client Host header not sent #18

Open
martensson opened this issue Jun 29, 2015 · 10 comments
Open

Client Host header not sent #18

martensson opened this issue Jun 29, 2015 · 10 comments

Comments

@martensson
Copy link

Hi @klizhentas !

First thanks for this great library and open sourcing it. I am currently using it in a different project (https://github.com/martensson/moxy) and it's working great so far. But I encountered a deal breaking bug that would be nice to fix, which is that oxy does not respect the clients Host header being sent.
This causes problems when you want to route traffic to nodes that respond differently depending on vhost settings.

Being a transparent reverse proxy the library should maintain all header as they are unless its a way to override them at least. I checked the code and saw a quick fix to the problem, and there is a PR that you can check out.

If you believe there is a better way of doing it please tell me, if not I will have to fork oxy just because of this small fix, and I hope not :/

Thanks!

Best regards,
Benjamin

@KensoDev
Copy link

KensoDev commented Jul 1, 2015

@martensson Is the Host header the only one that doesn't pass to the origins?

@martensson
Copy link
Author

@KensoDev from my tests it seems all other Headers are passed just fine, it's just the Host header that is handled differently by Go for reasons I still don't know why. There are a few exceptions thought (https://github.com/mailgun/oxy/blob/master/forward/headers.go#L22-L31) that should normally be safe to remove.

But the X-Forwarded-Host that is added by oxy is also wrong, since its just a copy of the normal Host Header.

I did some more digging into the code and saw that we can actually just remove the following two lines: https://github.com/mailgun/oxy/blob/master/forward/fwd.go#L125-L126 and it would solve the whole problem. Even better than my previous PR and saves two unnecessary lines of code. :)

@pquerna
Copy link
Contributor

pquerna commented Aug 11, 2015

+1, have this same problem. currently we hacked in a patch to copy the host header and XFH from the original request, not from the target url:

--- a/Godeps/_workspace/src/github.com/mailgun/oxy/forward/fwd.go
+++ b/Godeps/_workspace/src/github.com/mailgun/oxy/forward/fwd.go
@@ -147,5 +147,11 @@ func (f *Forwarder) copyRequest(req *http.Request, u *url.URL) *http.Request {
        if f.rewriter != nil {
                f.rewriter.Rewrite(outReq)
        }
+
+       // TODO(pquerna): HACK HACK HACK HACK HACK HACK
+       // We need to fix Header Host mapping in vulcan.
+       outReq.Header.Set(XForwardedHost, req.Host)
+       outReq.Host = req.Host
+
        return outReq
 }

@pquerna
Copy link
Contributor

pquerna commented Aug 11, 2015

CC @klizhentas

@martensson
Copy link
Author

@pquerna this is already fixed in a PR some weeks ago :)

@uaalto
Copy link

uaalto commented Oct 2, 2015

Hi! I'm still experiencing the same bug. Is it really fixed in that PR?

@martensson
Copy link
Author

@uaalto it should work fine, did you set the option? https://godoc.org/github.com/mailgun/oxy/forward#PassHostHeader

@uaalto
Copy link

uaalto commented Oct 5, 2015 via email

@martensson
Copy link
Author

hmm I am running my own proxy with oxy in the core without problem, and I am getting the client host headers as well. Well I am glad it worked out for you! :)

@pquerna
Copy link
Contributor

pquerna commented Oct 5, 2015

couldn't get it working in vulcan, so we are still applying the patch to oxy.

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

4 participants