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

[BUG] panic: interface conversion: http.RoundTripper is nil, not *http.Transport #803

Open
febelery opened this issue Oct 18, 2024 · 2 comments
Labels

Comments

@febelery
Copy link
Contributor

使用的版本

  • SDK 版本:v2.1.7

报错文件 util/http.go#293

// httpWithTLS CA 证书
func httpWithTLS(rootCa, key string) (*http.Client, error) {
	var client *http.Client
	certData, err := os.ReadFile(rootCa)
	if err != nil {
		return nil, fmt.Errorf("unable to find cert path=%s, error=%v", rootCa, err)
	}
	cert := pkcs12ToPem(certData, key)
	config := &tls.Config{
		Certificates: []tls.Certificate{cert},
	}
	trans := (DefaultHTTPClient.Transport.(*http.Transport)).Clone()
	trans.TLSClientConfig = config
	trans.DisableCompression = true
	client = &http.Client{Transport: trans}
	return client, nil
}

trans := (DefaultHTTPClient.Transport.(*http.Transport)).Clone()

DefaultHTTPClient.Transport 这个为nil

复现地址

https://go.dev/play/p/3a4o6ObftCg

@febelery febelery added the bug label Oct 18, 2024
@febelery
Copy link
Contributor Author

util/http.go 文件第26行可以改成

var DefaultHTTPClient = &http.Client{
    Transport: http.DefaultTransport,
}

@houseme
Copy link
Collaborator

houseme commented Oct 19, 2024

欢迎贡献PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants