Commit Graph

42 Commits

Author SHA1 Message Date
Canelo Hill 688592ebe6 Improve client/server tests
Tests must not call *testing.T methods after the test function returns.
Use a sync.WaitGroup to ensure that server handler functions complete
before tests return.
2024-06-19 17:11:11 +10:00
Canelo Hill a70cea529a
Update for deprecated ioutil package (#931) 2024-06-19 14:44:41 +10:00
apoorvajagtap ce903f6d1d Reverts to v1.5.0
This commit reverts the changes back till 8983b96324.
And inherits the README.md changes of 931041c5ee
Relates to:
- https://github.com/gorilla/websocket/issues/880#issuecomment-2081189055
2024-06-13 23:18:03 -04:00
apoorvajagtap 1bddf2e0db bumps go version & removes deprecated module usage 2024-05-01 18:51:54 +05:30
apoorvajagtap b2c246b2ec Revert " Update go version & add verification/testing tools (#840)"
This reverts commit 666c197fc9.
2024-05-01 18:51:54 +05:30
apoorvajagtap 09a6bab466 removing error handling while closing connections 2024-04-01 22:33:57 -04:00
apoorvajagtap 58af150309 return errors instead of printing to logs 2024-04-01 22:33:57 -04:00
merlin 4a5e66f763 make tests parallel 2024-01-21 22:46:55 -05:00
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
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
Rn 2c89656910
Modify http Method String Literal to Variable (#728) 2021-12-19 11:21:45 -05: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
Dave Baker ed9368d0b7
typo (#583) 2020-03-19 06:46:44 -07:00
Steven Scott cdd40f587d Add comprehensive host test (#429)
Add table driven test for handling of host in request URL, request
header and TLS server name. In addition to testing various uses of host
names, this test also confirms that host names are handled the same as
the net/http client.

The new table driven test replaces TestDialTLS, TestDialTLSNoverify,
TestDialTLSBadCert and TestHostHeader.

Eliminate duplicated code for constructing root CA.
2018-09-24 16:10:46 -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
SALLEYRON Julien ceae45234a Add context in the Dialer 2018-08-24 13:45:12 -07:00
dottyjones badcf87185
Improve names in handshake deadline test 2018-05-28 12:07:56 -07:00
dottyjones f90b62c3ce
Add test for handshake deadline 2018-05-28 07:28:04 -07:00
unknown 0647012449 Modify http status code to variable 2018-02-28 13:09:02 -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
Gary Burd 8c6cfd493d
Improve bad handshake error text
Change the error text for bad handshake errors from

    websocket: not a websocket handshake:

to:

    websocket: the client is not using the websocket protocol:

The new text should be more helpful to developers who do not know or
understand the details of the protocol.

Test for bad handshake before other request errors.
2017-11-30 16:45:44 -08:00
Gary Burd 3da6ca0cb6 Simplify and fix spelling errors in test files
Simplify using gofmt -s.
2017-11-02 08:08:30 -07:00
Jérôme Bernard 71fa72d484 Replace parseURL() with net/url.Parse() (#290) 2017-10-12 19:08:58 -07: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
Gary Burd 2d1e4548da Simplify dial TLS test
There's no need to fake the connection to example.com because 127.0.0.1
is a host in the net/http/httptest certificate.
2016-09-12 08:30:41 -07:00
Seiichi KONDO 360dfe00ec Support proxy authorization for websocket client 2016-02-17 21:46:45 +09:00
Gary Burd 9727ab9cda Test URL path and query 2015-12-15 20:25:50 -08:00
Gary Burd 567453a710 Require GET in Upgrader.Upgrade.
Return error if the request method is not GET.

Remove all request method tests from the examples.
2015-11-02 09:08:11 -08:00
Gary Burd a4e0143e1f Do not allow duplicate headers in handshake 2015-11-02 08:39:02 -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
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 411599d366 Cleanup client/server tests. 2014-07-05 08:49:11 -07:00
Gary Burd 0f32413e5e Relax default origin test.
Update the default origin test to treat no origin specified as OK. If
the client can create a request without the origin set, then the client
can also create a request with an arbitrary origin.
2014-06-30 14:57:20 -07:00
Gary Burd bbe4cde693 Use Upgrader in client/server test. 2014-04-20 12:08:24 -07:00
Gary Burd 15aed3b4a4 Relicense to the Gorilla WebSocket Authors. 2014-04-18 14:25:11 -07: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