-
Notifications
You must be signed in to change notification settings - Fork 619
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
Using upstream hostname for request (#294) #301
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable. A couple of comments;
-
Please roll the two tests into one. You can define a routing table with two entries and then use
t.Run
subtests to test the two cases. -
For boolean flags the
=true
or=false
is redundant since the existence or non-existence of the option is sufficient. Inroute.go
you can use_, t.UseUpstreamHostame = r.Opts["..."]
to achieve this. -
I think the name
UseUpstreamHostname
is too long. Can you think of something shorter and less verbose, e.g.fwdhost
,usehost
,upstreamhost
, ... I don't have better ideas either.
|
You can replace the tests with this: func TestProxyUsehost(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, r.Host)
}))
proxy := httptest.NewServer(&HTTPProxy{
Transport: &http.Transport{
Dial: func(network, addr string) (net.Conn, error) {
addr = server.URL[len("http://"):]
return net.Dial(network, addr)
},
},
Lookup: func(r *http.Request) *route.Target {
routes := "route add mock /usehost http://a.com/ opts \"usehost\"\n"
routes += "route add mock / http://a.com/"
tbl, _ := route.NewTable(routes)
return tbl.Lookup(r, "", route.Picker["rr"], route.Matcher["prefix"])
},
})
defer proxy.Close()
check := func(uri, host string) {
resp, body := mustGet(proxy.URL + uri)
if got, want := resp.StatusCode, http.StatusOK; got != want {
t.Fatalf("got status %d want %d", got, want)
}
if got, want := string(body), host; got != want {
t.Fatalf("got body %q want %q", got, want)
}
}
proxyHost := proxy.URL[len("http://"):]
t.Run("use host", func(t *testing.T) { check("/usehost", "a.com") })
t.Run("no host", func(t *testing.T) { check("/", proxyHost) })
}
Thx a lot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some small comments. The rest looks good.
route/route.go
Outdated
@@ -71,7 +71,11 @@ func (r *Route) addTarget(service string, targetURL *url.URL, fixedWeight float6 | |||
if r.Opts != nil { | |||
t.StripPath = r.Opts["strip"] | |||
t.TLSSkipVerify = r.Opts["tlsskipverify"] == "true" | |||
t.UseUpstreamHostname = r.Opts["useupstreamhostname"] == "true" | |||
// If the 'usehost' key exists in the map, we set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant. Just use what I wrote initially
_, t.UseHost = r.Opts["usehost"]
route/target.go
Outdated
@@ -21,10 +21,10 @@ type Target struct { | |||
// TLS connections. | |||
TLSSkipVerify bool | |||
|
|||
// UseUpstreamHostname causes the origin host header to be | |||
// UseHost causes the origin host header to be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UseHost determines whether the the origin or the target hostname
is used for the upstream request
route/route.go
Outdated
@@ -73,9 +73,7 @@ func (r *Route) addTarget(service string, targetURL *url.URL, fixedWeight float6 | |||
t.TLSSkipVerify = r.Opts["tlsskipverify"] == "true" | |||
// If the 'usehost' key exists in the map, we set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you drop the comment, too please? Don't want to be overly pick but it really is redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No Worries. It looks like I need to rerun the build anyways. :-D
I'll let this sit for another day or two before I merge it. |
@magiconair, how about |
How about |
ooooo.... that's way better. Default will be |
Yes. I think that makes more sense and provides some flexibility for the future. boolean flags are always somewhat limiting unless you can be absolutely sure that there will ever only be two choices. |
Can you make that change? |
I'm on it! |
Two small changes and then we can merge it. |
Thats a bummer. It looks like an unstable test. :-( |
No description provided.