From 972bf7152692a3127d4e6c851859985d1ff23d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo?= Date: Wed, 18 Nov 2020 11:22:59 +0100 Subject: [PATCH] Added DialTLS. Removed a comment in tests --- client.go | 25 ++++++++++++++++++------- frame_test.go | 1 - 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index e1d8ff7..95401db 100644 --- a/client.go +++ b/client.go @@ -81,15 +81,29 @@ func client(c net.Conn, url string, r *fasthttp.Request) (conn *Conn, err error) // // url parameter must follow WebSocket URL format i.e. ws://host:port/path func Dial(url string) (*Conn, error) { - return dial(url, nil) + cnf := &tls.Config{ + InsecureSkipVerify: false, + MinVersion: tls.VersionTLS11, + } + return dial(url, cnf, nil) +} + +// DialTLS establishes a websocket connection as client with the +// parsed tls.Config. The config will be used if the URL is wss:// like. +func DialTLS(url string, cnf *tls.Config) (*Conn, error) { + return dial(url, cnf, nil) } // DialWithHeaders establishes a websocket connection as client sending a personalized request. func DialWithHeaders(url string, req *fasthttp.Request) (*Conn, error) { - return dial(url, req) + cnf := &tls.Config{ + InsecureSkipVerify: false, + MinVersion: tls.VersionTLS11, + } + return dial(url, cnf, req) } -func dial(url string, req *fasthttp.Request) (conn *Conn, err error) { +func dial(url string, cnf *tls.Config, req *fasthttp.Request) (conn *Conn, err error) { uri := fasthttp.AcquireURI() defer fasthttp.ReleaseURI(uri) uri.Update(url) @@ -114,10 +128,7 @@ func dial(url string, req *fasthttp.Request) (conn *Conn, err error) { if scheme == "http" { c, err = net.Dial("tcp", b2s(addr)) } else { - c, err = tls.Dial("tcp", b2s(addr), &tls.Config{ - InsecureSkipVerify: false, - MinVersion: tls.VersionTLS11, - }) + c, err = tls.Dial("tcp", b2s(addr), cnf) } if err == nil { conn, err = client(c, uri.String(), req) diff --git a/frame_test.go b/frame_test.go index c60ccca..56c009d 100644 --- a/frame_test.go +++ b/frame_test.go @@ -14,7 +14,6 @@ var ( func TestIssue11(t *testing.T) { fr := AcquireFrame() - // fr.SetBinary() fr.SetClose() fr.SetFin() fr.setLength(1)