Commit Graph

317 Commits

Author SHA1 Message Date
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
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
Adam Shannon 5fb94172f4 drop Go versions prior to 1.7 in CI
* drop Go versions prior to 1.7 in CI

* consolidate conn*.go files after dropping old Go support
2018-08-22 14:10:37 -07:00
stevenscott89 3ff3320c2a Improve server subprotocol documentation
Partial fix for 404.
2018-08-16 15:18:03 -07:00
Matt Silverlock 5ed622c449 Update LICENSE file to reflect Google employee contributions. 2018-06-05 13:25:52 -07:00
Kamil Kisiel c17c80cb48
Merge pull request #385 from dottyjones/master
Add test for handshake deadline
2018-05-28 18:35:52 -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
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
Petr cd94665a65 Minor fixes in comments
* Fix typo

"netowrk" is a misspelling of "network"

* Fix export comment

Comment on exported type Hub should be of the form "Hub ..." (golint)
2018-04-15 20:20:28 -07:00
Gary Burd eb92580837
Use net.Buffers to write multiple slices to connection
Closes #346.
2018-03-06 10:15:48 -08: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
Carter Jones 6656ddce91 add newline and remove extra space 2018-03-04 15:22:45 -08:00
unknown 0647012449 Modify http status code to variable 2018-02-28 13:09:02 -08:00
Gary Burd f37d158860 Travis config: add Go 1.10.x, revert 1.4.x to 1.4
1.4.x is missing go vet
2018-02-18 23:13:02 -08:00
Alexey Palazhchenko 2967b101a5 Use latest patch releases of Go 2018-02-18 23:13:02 -08:00
claudia-jones 8fbc40be62 Simplify echo example client (#349)
Use existing `done` channel to signal that reader is done instead of closing the connection.
2018-02-18 16:00:50 -08:00
Gary Burd 4ac909741d
Improve control message handler doc
Fixes #338
2018-01-31 17:52:56 -08:00
Gary Burd 91f589db02
Improve check origin documentation
Remove the example code to disable origin checks from the documentation.
I am concerned that developers are copying the code without
understanding the security implications of the code. Most applications
should not use this code.

Change the bad origin error message to mention Upgrader.CheckOrigin

Mention cross-site request forgery in the Upgrader.CheckOrigin doc.
2018-01-25 10:51:21 -08:00
Gary Burd 292fd08b25
Replace "frame" with "message" in documentation
The documentation sometimes used the term "frame" when referring to
single frame control messages.  Use the term "message" for consistency
in the documentation and to hide a detail that most application
programmers do not need to know about.
2018-01-10 06:15:25 -08:00
Gary Burd 58729a2165
Don't log 1006 error in chat example
This error is expected (Safari closes connections without sending a close
frame).

Fixes #323
2018-01-09 12:15:58 -08:00
Gary Burd d965e9adc6
Handle no status in FormatCloseMessage
Return empty message for CloseNoStatusReceived. This status indicates
that the message is empty, so make it so. Because it's illegal to send
CloseNoStatusReceived, this change should not break a correct
application.
2017-12-28 07:29:59 -08:00
Jordan Pittier cdedf21e58 examples/chat/client.go: avoid allocating []byte{} for PingMessage (#312)
It's useless and only gives more work to the GC.
2017-12-09 19:53:53 -08:00
Gary Burd c55883f973
Add parseExtensions test case (#310) 2017-12-05 11:45:40 -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
fising 2b58522131 update README.md 2017-11-29 07:20:15 -08:00
David Dollar b648f206c2 Use ASCII case folding in same origin test 2017-11-27 16:10:45 -08:00
Gary Burd 23059f2957 Update with gofmt on tip
The changes are compatible with older versions of gofmt.
2017-11-23 00:11:29 -08:00
Gary Burd 447c2df769 Compare request header tokens with ASCII case folding
Compare request header tokens with ASCII case folding per the WebSocket
RFC.
2017-11-22 23:15:27 -08:00
Gary Burd aa5ed01c91 Improve control message handling documentation
Closes #299
2017-11-19 13:55:18 -08:00
Sebastian Waisbrot 7ca4275b84 More consistent error handling in doc
I noticed the example is actually wrong as the same block both calls `return` with no parameter and `return err`. I think it would be better to allow the code to be used directly. I added calls to log.Println as it was used on the other example as it might be more useful for newcomers to see error messages.
2017-11-12 07:44:06 -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
Gary Burd f918560c4c Improve NextWriter documentation 2017-10-10 09:16:43 -07:00
xPushkin c908dc801c Typo fix
Just a small typo fix.
2017-10-07 13:56:17 -07:00
Gary Burd 4201258b82 Merge pull request #286 from alaingilbert/patch-1
Add missing html tag in example/echo
2017-09-26 16:33:35 -07:00
Alain Gilbert 5755884efa
Add missing html tag in example/echo 2017-09-26 16:13:09 -07:00
Gary Burd 6f34763140 Add Go 1.9 to Travis config 2017-09-13 22:11:54 -07:00
Gary Burd a69d9f6de4 Merge branch 'updoc' 2017-07-18 13:23:41 -07:00
Gary Burd 92f772e4b3 Misc cleanup
- Fix lint warnings.
- Use standard comment format to mark deprecated identifiers.
- Remove redundant paragraph from doc.
2017-07-18 13:21:30 -07:00
fuzzybear3965 f4f69d2d8d implementing (some of) @garyburd's suggestions 2017-07-10 10:21:27 -04:00
Gary Burd 462d5c5828 Merge pull request #261 from kybin/master
doc: use ":=" when check error for conn.WriteMessage
2017-07-08 03:26:55 -04:00
fuzzybear3965 1d375d5a0d distinguish Upgrader.Upgrade from Upgrade 2017-07-07 14:47:14 -04:00