mirror of
https://github.com/fumiama/terasu.git
synced 2026-06-11 05:30:26 +08:00
fix: tls conn nil pointer
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHTTPDialTLS(t *testing.T) {
|
||||
func TestHTTPDialTLS13(t *testing.T) {
|
||||
cli := http.Client{
|
||||
Transport: &http.Transport{
|
||||
DialTLS: func(network, addr string) (net.Conn, error) {
|
||||
@@ -38,3 +38,35 @@ func TestHTTPDialTLS(t *testing.T) {
|
||||
}
|
||||
t.Log(string(data))
|
||||
}
|
||||
|
||||
func TestHTTPDialTLS12(t *testing.T) {
|
||||
cli := http.Client{
|
||||
Transport: &http.Transport{
|
||||
DialTLS: func(network, addr string) (net.Conn, error) {
|
||||
conn, err := net.Dial("tcp", "18.65.159.2:443")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t.Log("net.Dial succeeded")
|
||||
return Use(tls.Client(conn, &tls.Config{
|
||||
ServerName: "huggingface.co",
|
||||
InsecureSkipVerify: true,
|
||||
MaxVersion: tls.VersionTLS12,
|
||||
})), nil
|
||||
},
|
||||
},
|
||||
}
|
||||
resp, err := cli.Get("https://huggingface.co/")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatal("status code:", resp.StatusCode)
|
||||
}
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(string(data))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user