dial.go 678 B

1234567891011121314151617181920212223242526272829
  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package websocket
  5. import (
  6. "context"
  7. "crypto/tls"
  8. "net"
  9. )
  10. func dialWithDialer(ctx context.Context, dialer *net.Dialer, config *Config) (conn net.Conn, err error) {
  11. switch config.Location.Scheme {
  12. case "ws":
  13. conn, err = dialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
  14. case "wss":
  15. tlsDialer := &tls.Dialer{
  16. NetDialer: dialer,
  17. Config: config.TlsConfig,
  18. }
  19. conn, err = tlsDialer.DialContext(ctx, "tcp", parseAuthority(config.Location))
  20. default:
  21. err = ErrBadScheme
  22. }
  23. return
  24. }