Skip to content

Commit

Permalink
Added DialTLS. Removed a comment in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrr committed Nov 18, 2020
1 parent 978d566 commit 972bf71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
25 changes: 18 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var (

func TestIssue11(t *testing.T) {
fr := AcquireFrame()
// fr.SetBinary()
fr.SetClose()
fr.SetFin()
fr.setLength(1)
Expand Down

0 comments on commit 972bf71

Please sign in to comment.