diff --git a/pkg/ffresty/ffresty.go b/pkg/ffresty/ffresty.go index ed5f677..31cb863 100644 --- a/pkg/ffresty/ffresty.go +++ b/pkg/ffresty/ffresty.go @@ -256,9 +256,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 diff --git a/pkg/ffresty/ffresty_test.go b/pkg/ffresty/ffresty_test.go index 255d416..5580cd5 100644 --- a/pkg/ffresty/ffresty_test.go +++ b/pkg/ffresty/ffresty_test.go @@ -633,7 +633,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())