forked from mirror/websocket
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.
This commit is contained in:
parent
ceae45234a
commit
a9dd6e8839
|
@ -7,6 +7,7 @@ matrix:
|
||||||
- go: 1.8.x
|
- go: 1.8.x
|
||||||
- go: 1.9.x
|
- go: 1.9.x
|
||||||
- go: 1.10.x
|
- go: 1.10.x
|
||||||
|
- go: 1.11.x
|
||||||
- go: tip
|
- go: tip
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- go: tip
|
- go: tip
|
||||||
|
|
|
@ -133,7 +133,7 @@ var DefaultDialer = &Dialer{
|
||||||
}
|
}
|
||||||
|
|
||||||
// nilDialer is dialer to use when receiver is nil.
|
// nilDialer is dialer to use when receiver is nil.
|
||||||
var nilDialer Dialer = *DefaultDialer
|
var nilDialer = *DefaultDialer
|
||||||
|
|
||||||
// DialContext creates a new client connection. Use requestHeader to specify the
|
// DialContext creates a new client connection. Use requestHeader to specify the
|
||||||
// origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies (Cookie).
|
// origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies (Cookie).
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// +build go1.7
|
|
||||||
|
|
||||||
package websocket
|
package websocket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
// this source code is governed by a BSD-style license that can be found in the
|
// this source code is governed by a BSD-style license that can be found in the
|
||||||
// LICENSE file.
|
// LICENSE file.
|
||||||
|
|
||||||
// Require 1.7 for sub-bencmarks
|
// !appengine
|
||||||
// +build go1.7,!appengine
|
|
||||||
|
|
||||||
package websocket
|
package websocket
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
type PreparedMessage struct {
|
type PreparedMessage struct {
|
||||||
messageType int
|
messageType int
|
||||||
data []byte
|
data []byte
|
||||||
err error
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
frames map[prepareKey]*preparedFrame
|
frames map[prepareKey]*preparedFrame
|
||||||
}
|
}
|
||||||
|
|
10
server.go
10
server.go
|
@ -8,7 +8,6 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -171,17 +170,12 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
netConn net.Conn
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
h, ok := w.(http.Hijacker)
|
h, ok := w.(http.Hijacker)
|
||||||
if !ok {
|
if !ok {
|
||||||
return u.returnError(w, r, http.StatusInternalServerError, "websocket: response does not implement http.Hijacker")
|
return u.returnError(w, r, http.StatusInternalServerError, "websocket: response does not implement http.Hijacker")
|
||||||
}
|
}
|
||||||
var brw *bufio.ReadWriter
|
var brw *bufio.ReadWriter
|
||||||
netConn, brw, err = h.Hijack()
|
netConn, brw, err := h.Hijack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return u.returnError(w, r, http.StatusInternalServerError, err.Error())
|
return u.returnError(w, r, http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -331,7 +325,7 @@ func IsWebSocketUpgrade(r *http.Request) bool {
|
||||||
tokenListContainsValue(r.Header, "Upgrade", "websocket")
|
tokenListContainsValue(r.Header, "Upgrade", "websocket")
|
||||||
}
|
}
|
||||||
|
|
||||||
// bufioReader size returns the size of a bufio.Reader.
|
// bufioReaderSize size returns the size of a bufio.Reader.
|
||||||
func bufioReaderSize(originalReader io.Reader, br *bufio.Reader) int {
|
func bufioReaderSize(originalReader io.Reader, br *bufio.Reader) int {
|
||||||
// This code assumes that peek on a reset reader returns
|
// This code assumes that peek on a reset reader returns
|
||||||
// bufio.Reader.buf[:0].
|
// bufio.Reader.buf[:0].
|
||||||
|
|
|
@ -58,9 +58,9 @@ var checkSameOriginTests = []struct {
|
||||||
ok bool
|
ok bool
|
||||||
r *http.Request
|
r *http.Request
|
||||||
}{
|
}{
|
||||||
{false, &http.Request{Host: "example.org", Header: map[string][]string{"Origin": []string{"https://other.org"}}}},
|
{false, &http.Request{Host: "example.org", Header: map[string][]string{"Origin": {"https://other.org"}}}},
|
||||||
{true, &http.Request{Host: "example.org", Header: map[string][]string{"Origin": []string{"https://example.org"}}}},
|
{true, &http.Request{Host: "example.org", Header: map[string][]string{"Origin": {"https://example.org"}}}},
|
||||||
{true, &http.Request{Host: "Example.org", Header: map[string][]string{"Origin": []string{"https://example.org"}}}},
|
{true, &http.Request{Host: "Example.org", Header: map[string][]string{"Origin": {"https://example.org"}}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckSameOrigin(t *testing.T) {
|
func TestCheckSameOrigin(t *testing.T) {
|
||||||
|
|
2
util.go
2
util.go
|
@ -178,7 +178,7 @@ headers:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseExtensiosn parses WebSocket extensions from a header.
|
// parseExtensions parses WebSocket extensions from a header.
|
||||||
func parseExtensions(header http.Header) []map[string]string {
|
func parseExtensions(header http.Header) []map[string]string {
|
||||||
// From RFC 6455:
|
// From RFC 6455:
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue