Skip to content

Commit 563d514

Browse files
gernestfurkansenharputlu
authored andcommitted
[TT-278] Fix ensuring transport to upstream (#3329)
* Fix ensuring transport to upstream Fixes #3259 This refactors EnsureTransport function for properly ensuring transport is present on the host when load balancer is enabled. We rely on url.Parse to do heavy lifting. We add missing Scheme field to make sure URL.String will return a valid upstream host. * use http when scheme and protocol are missing
1 parent 18312b4 commit 563d514

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

gateway/reverse_proxy.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ func nextTarget(targetData *apidef.HostList, spec *APISpec) (string, error) {
157157
}
158158

159159
host := EnsureTransport(gotHost, spec.Protocol)
160-
161160
if !spec.Proxy.CheckHostAgainstUptimeTests {
162161
return host, nil // we don't care if it's up
163162
}

gateway/reverse_proxy_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,3 +1028,23 @@ func BenchmarkCopyRequestResponse(b *testing.B) {
10281028
}
10291029
}
10301030
}
1031+
1032+
func TestEnsureTransport(t *testing.T) {
1033+
cases := []struct {
1034+
host, protocol, expect string
1035+
}{
1036+
{"https://httpbin.org ", "https", "https://httpbin.org"},
1037+
{"httpbin.org ", "https", "https://httpbin.org"},
1038+
{"http://httpbin.org ", "https", "http://httpbin.org"},
1039+
{"httpbin.org ", "tls", "tls://httpbin.org"},
1040+
{"httpbin.org ", "", "http://httpbin.org"},
1041+
}
1042+
for i, v := range cases {
1043+
t.Run(fmt.Sprintf("case-%d", i), func(t *testing.T) {
1044+
g := EnsureTransport(v.host, v.protocol)
1045+
if g != v.expect {
1046+
t.Errorf("expected %q got %q", v.expect, g)
1047+
}
1048+
})
1049+
}
1050+
}

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
2121
github.com/bshuster-repo/logrus-logstash-hook v0.4.1
2222
github.com/buger/jsonparser v1.1.1
23-
github.com/cenk/backoff v2.2.1+incompatible // indirect
23+
github.com/cenk/backoff v2.2.1+incompatible
2424
github.com/cenkalti/backoff/v4 v4.0.2
2525
github.com/certifi/gocertifi v0.0.0-20190905060710-a5e0173ced67 // indirect
2626
github.com/clbanning/mxj v1.8.4
@@ -29,6 +29,8 @@ require (
2929
github.com/emanoelxavier/openid2go v0.0.0-20190718021401-6345b638bfc9 // indirect
3030
github.com/evalphobia/logrus_sentry v0.8.2
3131
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
32+
github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf // indirect
33+
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8
3234
github.com/gemnasium/logrus-graylog-hook v2.0.7+incompatible
3335
github.com/getkin/kin-openapi v0.32.0
3436
github.com/getsentry/raven-go v0.2.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a h1:yDWHCSQ40h88yi
121121
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a/go.mod h1:7Ga40egUymuWXxAe151lTNnCv97MddSOVsjpPPkityA=
122122
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
123123
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
124+
github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf h1:NrF81UtW8gG2LBGkXFQFqlfNnvMt9WdB46sfdJY4oqc=
125+
github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf/go.mod h1:VzmDKDJVZI3aJmnRI9VjAn9nJ8qPPsN1fqzr9dqInIo=
126+
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8 h1:a9ENSRDFBUPkJ5lCgVZh26+ZbGyoVJG7yb5SSzF5H54=
127+
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
124128
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
125129
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
126130
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=

0 commit comments

Comments
 (0)