Skip to content

Commit

Permalink
fix test and making host parsing logic more robust
Browse files Browse the repository at this point in the history
Signed-off-by: hfuss <hayden.fuss@kaleido.io>
  • Loading branch information
onelapahead committed Dec 20, 2024
1 parent 4ac2fee commit 052c797
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions pkg/ffresty/ffresty.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,22 @@ func NewWithConfig(ctx context.Context, ffrestyConfig Config) (client *resty.Cli
}
rCtx := req.Context()
// Record host in context to avoid redundant parses in hooks
u, _ := url.Parse(_url)
host := u.Host
rCtx = context.WithValue(rCtx, hostCtxKey{}, host)
var u *url.URL
if req.URL != "" {
u, _ = url.Parse(req.URL)
}
// The req.URL might have only set a path i.e. /home, fallbacking to the base URL of the client.
// So if the URL is nil, that's likely the case and we'll derive the host from the configured
// based instead.
if u == nil && _url != "" {
u, _ = url.Parse(_url)
}
if u != nil && u.Host != "" {
host := u.Host
rCtx = context.WithValue(rCtx, hostCtxKey{}, host)
} else {
rCtx = context.WithValue(rCtx, hostCtxKey{}, "unknown")
}
rc := rCtx.Value(retryCtxKey{})
if rc == nil {
// First attempt
Expand Down
2 changes: 1 addition & 1 deletion pkg/ffresty/ffresty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ func TestMTLSClientWithServer(t *testing.T) {
var restyConfig = config.RootSection("resty")
InitConfig(restyConfig)
clientTLSSection := restyConfig.SubSection("tls")
restyConfig.Set(HTTPConfigURL, ln.Addr())
restyConfig.Set(HTTPConfigURL, ln.Addr()) // note this does not have https:// in the URL
clientTLSSection.Set(fftls.HTTPConfTLSEnabled, true)
clientTLSSection.Set(fftls.HTTPConfTLSKeyFile, privateKeyFile.Name())
clientTLSSection.Set(fftls.HTTPConfTLSCertFile, publicKeyFile.Name())
Expand Down

0 comments on commit 052c797

Please sign in to comment.