Commit Graph

42 Commits

Author SHA1 Message Date
kanozec 483fb8d7c3 Add "in bytes" to sizes in documentation 2018-10-30 07:45:53 -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
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
stevenscott89 3ff3320c2a Improve server subprotocol documentation
Partial fix for 404.
2018-08-16 15:18:03 -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
unknown 0647012449 Modify http status code to variable 2018-02-28 13:09:02 -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 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
David Dollar b648f206c2 Use ASCII case folding in same origin test 2017-11-27 16:10:45 -08: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
fuzzybear3965 1d375d5a0d distinguish Upgrader.Upgrade from Upgrade 2017-07-07 14:47:14 -04: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
Gary Burd 286b5c9371 Use bufio.Reader returned from hijack in upgrade
Use the bufio.Reader returned from hijack if the reader's buffer size is
equal to the buffer size specified in Upgrader.ReadBufferSize.
2017-03-01 09:36:54 -08:00
Gary Burd 0674c7c796 Improve upgrade error messages
Upgrade typically fails because the request is not a handshake, not
because the handshake is malformed. To help developers diagnose the
common case, state explicitly that the request is not a handshake in
error messages.

To help diagnose malformed requests, capitalize and 'quote' header names
in error messages.
2017-01-23 10:55:51 -08: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 b5389d0dc2 Implement RFC 6455, section 4.4 2016-06-29 13:56:55 -07:00
Gary Burd a622679ebd Add IsWebSocketUpgrade 2016-03-09 10:36:44 -08:00
Gary Burd 5c91b59efa Improve Upgrader.Upgrade doc 2016-02-21 13:34:30 -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 ab5b3a61f5 Improve server error messages
Update the error messages for missing 'Connection: upgrade' and
'Upgrade: websocket' tokens to indicate that the header might not be
present. The previous error message implied that the header is present,
but has the wrong value. This leads to some confusion for those
debugging connection problems.
2015-01-14 22:19:51 -08:00
Gary Burd 7d2ea39ebc Cleanup buffer size calculations. 2014-11-05 12:26:52 -08:00
Gary Burd 4292df70df Check and handle error return from hijack. 2014-08-15 20:25:38 -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 3d0e89148e Clear deadlines set by HTTP server. 2014-06-29 19:47:15 -07:00
Gary Burd 1e6e1281b0 Clear upgrader handshake deadline. 2014-04-21 06:28:28 -07:00
Gary Burd df94ef6daa Various improvements to Upgrader.
- Revert back to using Subprotocols []string. The protocol negotiation
  using Subprotocols should meet the needs of most applications.
  Applications are not locked into using this negotiation. An
  application can pick a protocol some other way and specify the
  protocol using the Sec-Websocket-Protocol response header.
- Parse the origin using url.Parse. This is the correct function to use
  when parsing a full URL.
- Improve comments.
2014-04-20 11:38:35 -07:00
Gary Burd 15aed3b4a4 Relicense to the Gorilla WebSocket Authors. 2014-04-18 14:25:11 -07:00
Joachim Bauch ecf9b98e31 Updated docs. 2014-04-18 00:40:10 +02:00
Joachim Bauch 0a7cd15dd1 Make subprotocol negotiation more flexible. 2014-04-18 00:25:32 +02:00
Joachim Bauch 2b15a66741 Simplified returning of errors. 2014-04-18 00:20:46 +02:00
Joachim Bauch b03dcbad2a Updated Origin check.
The host in the Origin header must match the host of the request by default.
2014-04-18 00:07:36 +02:00
Joachim Bauch f99474eb97 Renamed constants to match Go style guidelines. 2014-04-17 23:46:48 +02:00
Joachim Bauch 56543ef6d6 Moved Upgrader code to server implementation. 2014-04-17 23:45:40 +02:00
Joachim Bauch b2f990180a Implement Upgrader API (#6). 2014-04-16 17:25:17 +02:00
Gary Burd 9cdec41bda Improve Upgrade documentation. 2013-12-20 14:54:49 -08:00
Gary Burd b118f62ec0 Add subprotocol negotiation to Dialer. 2013-12-14 08:06:24 -08:00
Gary Burd 93b1570a27 Improve documentation.
- Introduce ReadMessage and WriteMessage before NextReader and
  NextWriter in the package comment. It's better to introduce the easy
  methods first.
- Move sections on message of types before the concurrency section.
2013-10-29 17:43:03 -07:00
Gary Burd 1627eef2a3 Improve documentation. 2013-10-27 08:34:33 -07:00
Gary Burd 80c1e5a741 Add Subprotocols helper function. 2013-10-26 06:52:30 -07:00
Gary Burd 273ecadfca Initial commit 2013-10-16 16:30:59 -07:00