Commit Graph

47 Commits

Author SHA1 Message Date
Corey Daley 666c197fc9
Update go version & add verification/testing tools (#840)
Fixes #

**Summary of Changes**

1.
2. 
3.

> PS: Make sure your PR includes/updates tests! If you need help with
this part, just ask!
2023-08-27 01:31:45 +05:30
Ye Sijun af47554f34 check error before GotConn for trace
Signed-off-by: Ye Sijun <junnplus@gmail.com>
2022-07-12 08:37:30 -07:00
Chan Kang bc7ce893c3
Check for and report bad protocol in TLSClientConfig.NextProtos (#788)
* return an error when Dialer.TLSClientConfig.NextProtos contains a protocol that is not http/1.1

* include the likely cause of the error in the error message

* check for nil-ness of Dialer.TLSClientConfig before attempting to run the check

* addressing the review

* move the NextProtos test into a separate file so that it can be run conditionally on go versions >= 1.14

* moving the new error check into existing http response error block to reduce the possibility of false positives

* wrapping the error in %w

* using %v instead of %w for compatibility with older versions of go

* Revert "using %v instead of %w for compatibility with older versions of go"

This reverts commit d34dd940ee.

* move the unit test back into the existing test code since golang build constraint is no longer necessary

Co-authored-by: Chan Kang <chankang@chankang17@gmail.com>
2022-06-21 10:54:14 -07:00
Lluis Campos 9111bb834a
Dialer: add optional method NetDialTLSContext (#746)
Fixes issue: https://github.com/gorilla/websocket/issues/745

With the previous interface, NetDial and NetDialContext were used for
both TLS and non-TLS TCP connections, and afterwards TLSClientConfig was
used to do the TLS handshake.

While this API works for most cases, it prevents from using more advance
authentication methods during the TLS handshake, as this is out of the
control of the user.

This commits introduces another a new dial method, NetDialTLSContext,
which is used when dialing for TLS/TCP. The code then assumes that the
handshake is done there and TLSClientConfig is not used.

This API change is fully backwards compatible and it better aligns with
net/http.Transport API, which has these two dial flavors. See:
https://pkg.go.dev/net/http#Transport

Signed-off-by: Lluis Campos <lluis.campos@northern.tech>
2022-01-03 17:59:52 -08:00
Gary Burd 4fad403619
Remove support for Go 1.8 2022-01-02 15:53:55 -08:00
Gary Burd bcef8431c9
Use context.Context in TLS handshake (#751)
Continued work on #730.
2022-01-01 08:43:22 -08:00
Rn 2c89656910
Modify http Method String Literal to Variable (#728) 2021-12-19 11:21:45 -05:00
Gary Burd b4b5d887ad
Document the allowed concurrency on Upgrader and Dialer (#636)
* Document allowed concurrency on Dialer.
* Document allowed concurrency on Upgrader.
2021-12-16 11:07:50 -08:00
Ran Benita 873e67e4d5
Fix how the client checks for presence of Upgrade: websocket, Connection: upgrade (#604)
The values of the `Upgrade` and `Connection` response headers can
contain multiple tokens, for example

    Connection: upgrade, keep-alive

The WebSocket RFC describes the checking of these as follows:

   2.  If the response lacks an |Upgrade| header field or the |Upgrade|
       header field contains a value that is not an ASCII case-
       insensitive match for the value "websocket", the client MUST
       _Fail the WebSocket Connection_.

   3.  If the response lacks a |Connection| header field or the
       |Connection| header field doesn't contain a token that is an
       ASCII case-insensitive match for the value "Upgrade", the client
       MUST _Fail the WebSocket Connection_.

It is careful to note "contains a value", "contains a token".

Previously, the client would reject with "bad handshake" if the header
doesn't contain exactly the value it looks for.

Change the checks to use `tokenListContainsValue` instead, which is
incidentally what the server is already doing for similar checks.
2020-08-20 06:43:18 -07:00
kanozec 483fb8d7c3 Add "in bytes" to sizes in documentation 2018-10-30 07:45:53 -07:00
Jeff R. Allen 76e4896901 Fix formatting problem in the docs. (#435)
Sorry for the dumbest PR ever, but this tiny addition of a period changes the formatting of this sentence from a header to a regular paragraph in godoc.
2018-10-11 19:01:31 -07:00
Mathias Fredriksson 66b9c49e59 Move context to first parameter in DialContext
Follows best practice and pkg/context documentation:

> The Context should be the first parameter, typically named ctx
2018-08-25 08:15:06 -07:00
Steven Scott a9dd6e8839 miscellaneous cleanup
- Add Go 1.11 to Travis config
- Use short variable declarations where possible.
- Remove unnecessary build tags after move to Go 1.7 min version.
- Simplify composite literals.
- Remove unused fields (err in PerparedMessage)
- Fix errors reported by golint and goword.
2018-08-24 14:03:26 -07:00
SALLEYRON Julien ceae45234a Add context in the Dialer 2018-08-24 13:45:12 -07:00
Steven Scott b378caee5b Add write buffer pooling
Add WriteBufferPool to Dialer and Upgrader. This field specifies a pool
to use for write operations on a connection.  Use of the pool can reduce
memory use when there is a modest write volume over a large number of
connections.

Use larger of hijacked buffer and buffer allocated for connection (if
any) as buffer for building handshake response. This decreases possible
allocations when building the handshake response.

Modify bufio reuse test to call Upgrade instead of the internal
newConnBRW. Move the test from conn_test.go to server_test.go because
it's a serer test.

Update newConn and newConnBRW:

- Move the bufio "hacks" from newConnBRW to separate functions and call
these functions directly from Upgrade.
- Rename newConn to newTestConn and move to conn_test.go. Shorten
argument list to common use case.
- Rename newConnBRW to newConn.
- Add pool code to newConn.
2018-08-22 14:11:59 -07:00
Gary Burd 21ab95fa12
Modify headers to match case used in RFC examples
Change the subprotocol and extension header names to match the case used
in RFC examples. Other headers names already match the case used in the
examples.

Although the headers names in the handshake are case insensitive, some
libraries expect the exact case used in the RFC examples. This change
allows the package to interoperate with those broken libraries.
2018-04-20 10:16:12 -07:00
Gary Burd 4835f71f2a Improve client default timeout code
- Remove duplicate code.
- Don't update deprecated functions.
2018-03-06 09:50:53 -08:00
Pablo Carranza 8c40c0b5bd Bump default handshake timetout to 45 seconds 2018-03-06 09:50:53 -08:00
Pablo Carranza 196b8d0585 Add a default handshake timeout of 5 seconds 2018-03-06 09:50:53 -08:00
Julien Salleyron e426f23f06 Sec-WebSocket-Protocol is capitalize instead of canonical 2018-03-06 09:05:33 -08:00
Gary Burd b89020ee79
Add SOCKS5 support
- Bundle the golang.org/x/net/proxy package to x_net_proxy.go. The
package contains a SOCKS5 proxy. The package is bundled to avoid adding
a dependency from the weboscket package to golang.org/x/net.
- Restructure the existing HTTP proxy code so the code can be used as a
dialer with the proxy package.
- Modify Dialer.Dial to use proxy.FromURL.
- Improve tests (avoid modifying package-level data, use timeouts in
tests, use correct proxy URLs in tests).

Fixes #297.
2017-11-30 17:43:01 -08:00
Jérôme Bernard 71fa72d484 Replace parseURL() with net/url.Parse() (#290) 2017-10-12 19:08:58 -07:00
Alexander Emelin 8dc1cf94c1 enable client compression based on response header 2017-03-19 11:36:38 +03:00
Gary Burd b258b4fadb Use bufio.Writer returned from hijack in upgrade
Reuse the buffer backing the bufio.Writer returned from hijack if that
buffer is large enough to be generally useful and
Upgrader.WriteBufferSize == 0.

Update the logic for reusing bufio.Reader returned from hijack to match
the logic for bufio.Reader:  The buffer backing the reader must be
sufficiently large to be generally useful and Upgrader.ReadBufferSize ==
0.

Improve the documentation for ReadBufferSize and WriterBufferSize in
Dialer and Upgrader.
2017-03-02 14:46:13 -08:00
William Wennerström 3f3e394da2 Update cloneTLSConfig to use Go 1.8 Config.Clone method 2017-02-18 08:27:10 -08:00
Maxime Heckel 56d95f2940 add cookie jar to dialer 2016-10-18 09:56:48 -07:00
Gary Burd a0ef436d00 compression: add tests, rename option 2016-10-17 17:30:22 -07:00
Cyrus Katrak c09b72d2ee per message compression; only no context modes 2016-10-14 12:08:39 -07:00
Gary Burd 5a00fb2e99 Do not shallow copy crypto/tls.Config
The Config contains a sync.Once that should not be copied.
2016-04-23 15:46:58 -07:00
Seiichi KONDO 360dfe00ec Support proxy authorization for websocket client 2016-02-17 21:46:45 +09:00
Gary Burd 3986be78bf Split raw query from opaque in URL parser
Prior to this change, the client passed query strings from the
application to the network via the net/url#URL.Opaque field. This works,
but may not be something the authors of the net/url and net/http
packages expect. To play it safe, this change parses the query string to
the net/url#URL.RawQuery field.
2015-12-15 21:10:58 -08:00
Gary Burd a4e0143e1f Do not allow duplicate headers in handshake 2015-11-02 08:39:02 -08:00
Gary Burd 044091b51d Fix lint warning 2015-11-02 08:25:46 -08:00
Mark Wolfe 70eca1b8e7 Add Proxy support for websocket clients.
- Uses `http.ProxyFromEnvironment` for configuration in line with the
golang standard library.
2015-10-23 09:28:47 +11:00
Gary Burd 5ed2f4547d Refactor client handshake
- To take advantage of the Host header cleanup in the net/http
  Request.Write method, use a net/http Request to write the handshake to
  the wire.
- Move code from the deprecated NewClientConn function to Dialer.Dial.
  This change makes it easier to add proxy support to Dialer.Dial. Add
  comment noting that NewClientConn is deprecated.
- Update the code so that parseURL can be replaced with net/url Parse.
  We need to wait until we can require 1.5 before making the swap.
2015-10-21 10:08:33 -07:00
Gary Burd 7f59b56ea4 Fix DefaultDialar value
Initialize as pointer to struct with zero values as as implied by the
doc comment. This initialization matches similar values in the standard
library.
2015-10-18 15:41:02 -07:00
Gary Burd 1551221275 Reject URIs containing user information
WebSocket URIs do not contain user information per section 3 of RFC
6455.

Fixes #65
2015-05-15 09:26:38 -07:00
Peter Waller 6fd0f867fe Allow separate specification of http/dial Hosts
Enable the Host: header to be customized in a Dialer.Dial call.

This is needed to implement websocket proxies.
2015-05-10 11:51:08 +01:00
Gary Burd b2fa8f6d58 Return response body on bad handshake.
The Dialer.Dial method returns an *http.Response on a bad handshake.
This CL updates the Dial method to include up to 1024 bytes of the
response body in the returned *http.Response. Applications may find the
response body helpful when debugging bad handshakes.

Fixes issue #62.
2015-05-08 15:39:37 -07:00
Gary Burd 7d2ea39ebc Cleanup buffer size calculations. 2014-11-05 12:26:52 -08:00
Gary Burd db7a2a1679 Improve client host header handling.
- Set request host header to substring of the URL. Do not add default
  port to string.
- Do not include port when verifying TLS host name.
2014-05-08 11:21:56 -07:00
Gary Burd 15aed3b4a4 Relicense to the Gorilla WebSocket Authors. 2014-04-18 14:25:11 -07:00
Gary Burd 707d1f6c6b Cleanup issues reported by golint. 2013-12-23 12:08:49 -08:00
Gary Burd f273336ae2 Modify client to work with Chrome debug server.
The Chrome debug server does not use case insensitive comparison on the
Connection header tokens as required by the HTTP RFC. Modify the client
to send "Connection: Upgrade" as expected by Chrome. Because this
matches the examples in the RFC, this change might improve
interoperability with other servers.
2013-12-21 08:44:58 -08:00
Gary Burd b118f62ec0 Add subprotocol negotiation to Dialer. 2013-12-14 08:06:24 -08:00
Gary Burd 87accaef66 Add Dialer. 2013-12-14 08:06:24 -08:00
Gary Burd 273ecadfca Initial commit 2013-10-16 16:30:59 -07:00