forked from cerc-io/plugeth
04e175b8ec
* rpc: implement websockets with github.com/gorilla/websocket This change makes package rpc use the github.com/gorilla/websocket package for WebSockets instead of golang.org/x/net/websocket. The new library is more robust and supports all WebSocket features including continuation frames. There are new tests for two issues with the previously-used library: - TestWebsocketClientPing checks handling of Ping frames. - TestWebsocketLargeCall checks whether the request size limit is applied correctly. * rpc: raise HTTP/WebSocket request size limit to 5MB * rpc: remove default origin for client connections The client used to put the local hostname into the Origin header because the server wanted an origin to accept the connection, but that's silly: Origin is for browsers/websites. The nobody would whitelist a particular hostname. Now that the server doesn't need Origin anymore, don't bother setting one for clients. Users who need an origin can use DialWebsocket to create a client with arbitrary origin if needed. * vendor: put golang.org/x/net/websocket back * rpc: don't set Origin header for empty (default) origin * rpc: add HTTP status code to handshake error This makes it easier to debug failing connections. * ethstats: use github.com/gorilla/websocket * rpc: fix lint
65 lines
3.9 KiB
Markdown
65 lines
3.9 KiB
Markdown
# Gorilla WebSocket
|
|
|
|
[![GoDoc](https://godoc.org/github.com/gorilla/websocket?status.svg)](https://godoc.org/github.com/gorilla/websocket)
|
|
[![CircleCI](https://circleci.com/gh/gorilla/websocket.svg?style=svg)](https://circleci.com/gh/gorilla/websocket)
|
|
|
|
Gorilla WebSocket is a [Go](http://golang.org/) implementation of the
|
|
[WebSocket](http://www.rfc-editor.org/rfc/rfc6455.txt) protocol.
|
|
|
|
### Documentation
|
|
|
|
* [API Reference](http://godoc.org/github.com/gorilla/websocket)
|
|
* [Chat example](https://github.com/gorilla/websocket/tree/master/examples/chat)
|
|
* [Command example](https://github.com/gorilla/websocket/tree/master/examples/command)
|
|
* [Client and server example](https://github.com/gorilla/websocket/tree/master/examples/echo)
|
|
* [File watch example](https://github.com/gorilla/websocket/tree/master/examples/filewatch)
|
|
|
|
### Status
|
|
|
|
The Gorilla WebSocket package provides a complete and tested implementation of
|
|
the [WebSocket](http://www.rfc-editor.org/rfc/rfc6455.txt) protocol. The
|
|
package API is stable.
|
|
|
|
### Installation
|
|
|
|
go get github.com/gorilla/websocket
|
|
|
|
### Protocol Compliance
|
|
|
|
The Gorilla WebSocket package passes the server tests in the [Autobahn Test
|
|
Suite](https://github.com/crossbario/autobahn-testsuite) using the application in the [examples/autobahn
|
|
subdirectory](https://github.com/gorilla/websocket/tree/master/examples/autobahn).
|
|
|
|
### Gorilla WebSocket compared with other packages
|
|
|
|
<table>
|
|
<tr>
|
|
<th></th>
|
|
<th><a href="http://godoc.org/github.com/gorilla/websocket">github.com/gorilla</a></th>
|
|
<th><a href="http://godoc.org/golang.org/x/net/websocket">golang.org/x/net</a></th>
|
|
</tr>
|
|
<tr>
|
|
<tr><td colspan="3"><a href="http://tools.ietf.org/html/rfc6455">RFC 6455</a> Features</td></tr>
|
|
<tr><td>Passes <a href="https://github.com/crossbario/autobahn-testsuite">Autobahn Test Suite</a></td><td><a href="https://github.com/gorilla/websocket/tree/master/examples/autobahn">Yes</a></td><td>No</td></tr>
|
|
<tr><td>Receive <a href="https://tools.ietf.org/html/rfc6455#section-5.4">fragmented</a> message<td>Yes</td><td><a href="https://code.google.com/p/go/issues/detail?id=7632">No</a>, see note 1</td></tr>
|
|
<tr><td>Send <a href="https://tools.ietf.org/html/rfc6455#section-5.5.1">close</a> message</td><td><a href="http://godoc.org/github.com/gorilla/websocket#hdr-Control_Messages">Yes</a></td><td><a href="https://code.google.com/p/go/issues/detail?id=4588">No</a></td></tr>
|
|
<tr><td>Send <a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">pings</a> and receive <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">pongs</a></td><td><a href="http://godoc.org/github.com/gorilla/websocket#hdr-Control_Messages">Yes</a></td><td>No</td></tr>
|
|
<tr><td>Get the <a href="https://tools.ietf.org/html/rfc6455#section-5.6">type</a> of a received data message</td><td>Yes</td><td>Yes, see note 2</td></tr>
|
|
<tr><td colspan="3">Other Features</tr></td>
|
|
<tr><td><a href="https://tools.ietf.org/html/rfc7692">Compression Extensions</a></td><td>Experimental</td><td>No</td></tr>
|
|
<tr><td>Read message using io.Reader</td><td><a href="http://godoc.org/github.com/gorilla/websocket#Conn.NextReader">Yes</a></td><td>No, see note 3</td></tr>
|
|
<tr><td>Write message using io.WriteCloser</td><td><a href="http://godoc.org/github.com/gorilla/websocket#Conn.NextWriter">Yes</a></td><td>No, see note 3</td></tr>
|
|
</table>
|
|
|
|
Notes:
|
|
|
|
1. Large messages are fragmented in [Chrome's new WebSocket implementation](http://www.ietf.org/mail-archive/web/hybi/current/msg10503.html).
|
|
2. The application can get the type of a received data message by implementing
|
|
a [Codec marshal](http://godoc.org/golang.org/x/net/websocket#Codec.Marshal)
|
|
function.
|
|
3. The go.net io.Reader and io.Writer operate across WebSocket frame boundaries.
|
|
Read returns when the input buffer is full or a frame boundary is
|
|
encountered. Each call to Write sends a single frame message. The Gorilla
|
|
io.Reader and io.WriteCloser operate on a single WebSocket message.
|
|
|