Skip to content

Commit a633a10

Browse files
committed
lint.sh: Pass
1 parent 9b5a15b commit a633a10

13 files changed

+40
-60
lines changed

accept.go

+2-37
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,10 @@ func acceptCompression(r *http.Request, w http.ResponseWriter, mode CompressionM
245245

246246
for _, ext := range websocketExtensions(r.Header) {
247247
switch ext.name {
248+
// We used to implement x-webkit-deflate-fram too but Safari has bugs.
249+
// See https://github.com/nhooyr/websocket/issues/218
248250
case "permessage-deflate":
249251
return acceptDeflate(w, ext, mode)
250-
// Disabled for now, see https://github.com/nhooyr/websocket/issues/218
251-
// case "x-webkit-deflate-frame":
252-
// return acceptWebkitDeflate(w, ext, mode)
253252
}
254253
}
255254
return nil, nil
@@ -283,40 +282,6 @@ func acceptDeflate(w http.ResponseWriter, ext websocketExtension, mode Compressi
283282
return copts, nil
284283
}
285284

286-
func acceptWebkitDeflate(w http.ResponseWriter, ext websocketExtension, mode CompressionMode) (*compressionOptions, error) {
287-
copts := mode.opts()
288-
// The peer must explicitly request it.
289-
copts.serverNoContextTakeover = false
290-
291-
for _, p := range ext.params {
292-
if p == "no_context_takeover" {
293-
copts.serverNoContextTakeover = true
294-
continue
295-
}
296-
297-
// We explicitly fail on x-webkit-deflate-frame's max_window_bits parameter instead
298-
// of ignoring it as the draft spec is unclear. It says the server can ignore it
299-
// but the server has no way of signalling to the client it was ignored as the parameters
300-
// are set one way.
301-
// Thus us ignoring it would make the client think we understood it which would cause issues.
302-
// See https://tools.ietf.org/html/draft-tyoshino-hybi-websocket-perframe-deflate-06#section-4.1
303-
//
304-
// Either way, we're only implementing this for webkit which never sends the max_window_bits
305-
// parameter so we don't need to worry about it.
306-
err := fmt.Errorf("unsupported x-webkit-deflate-frame parameter: %q", p)
307-
http.Error(w, err.Error(), http.StatusBadRequest)
308-
return nil, err
309-
}
310-
311-
s := "x-webkit-deflate-frame"
312-
if copts.clientNoContextTakeover {
313-
s += "; no_context_takeover"
314-
}
315-
w.Header().Set("Sec-WebSocket-Extensions", s)
316-
317-
return copts, nil
318-
}
319-
320285
func headerContainsTokenIgnoreCase(h http.Header, key, token string) bool {
321286
for _, t := range headerTokens(h, key) {
322287
if strings.EqualFold(t, token) {

autobahn_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var autobahnCases = []string{"*"}
3838
// and not excluded by excludedAutobahnCases. Adding cases here means excludedAutobahnCases
3939
// is niled.
4040
// TODO:
41-
var forceAutobahnCases = []string{}
41+
// var forceAutobahnCases = []string{}
4242

4343
func TestAutobahn(t *testing.T) {
4444
t.Parallel()

close_go113.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//go:build !go1.16
2-
// +build !go1.16
1+
//go:build !go1.16 && !js
32

43
package websocket
54

close_go116.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.16 && !js
32

43
package websocket
54

compress.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ func (sw *slidingWindow) init(n int) {
201201
}
202202

203203
p := slidingWindowPool(n)
204-
buf, ok := p.Get().([]byte)
204+
buf, ok := p.Get().(*[]byte)
205205
if ok {
206-
sw.buf = buf[:0]
206+
sw.buf = (*buf)[:0]
207207
} else {
208208
sw.buf = make([]byte, 0, n)
209209
}
@@ -215,7 +215,7 @@ func (sw *slidingWindow) close() {
215215
}
216216

217217
swPoolMu.Lock()
218-
swPool[cap(sw.buf)].Put(sw.buf)
218+
swPool[cap(sw.buf)].Put(&sw.buf)
219219
swPoolMu.Unlock()
220220
sw.buf = nil
221221
}

frame.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !js
2+
13
package websocket
24

35
import (

frame_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestHeader(t *testing.T) {
5555

5656
r := rand.New(rand.NewSource(time.Now().UnixNano()))
5757
randBool := func() bool {
58-
return r.Intn(1) == 0
58+
return r.Intn(2) == 0
5959
}
6060

6161
for i := 0; i < 10000; i++ {
@@ -67,9 +67,11 @@ func TestHeader(t *testing.T) {
6767
opcode: opcode(r.Intn(16)),
6868

6969
masked: randBool(),
70-
maskKey: r.Uint32(),
7170
payloadLength: r.Int63(),
7271
}
72+
if h.masked {
73+
h.maskKey = r.Uint32()
74+
}
7375

7476
testHeader(t, h)
7577
}

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.19
55
require (
66
github.com/gin-gonic/gin v1.9.1
77
github.com/gobwas/ws v1.3.0
8-
github.com/golang/protobuf v1.5.3
98
github.com/google/go-cmp v0.5.9
109
github.com/gorilla/websocket v1.5.0
1110
golang.org/x/time v0.3.0

go.sum

-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ github.com/gobwas/ws v1.3.0/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/K
2929
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
3030
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
3131
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
32-
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
33-
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
3432
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
3533
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
3634
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
@@ -87,7 +85,6 @@ golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
8785
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
8886
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
8987
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
90-
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
9188
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
9289
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
9390
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

internal/test/assert/assert.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"strings"
77
"testing"
88

9-
"github.com/golang/protobuf/proto"
109
"github.com/google/go-cmp/cmp"
1110
"github.com/google/go-cmp/cmp/cmpopts"
1211
)
@@ -15,7 +14,7 @@ import (
1514
func Diff(v1, v2 interface{}) string {
1615
return cmp.Diff(v1, v2, cmpopts.EquateErrors(), cmp.Exporter(func(r reflect.Type) bool {
1716
return true
18-
}), cmp.Comparer(proto.Equal))
17+
}))
1918
}
2019

2120
// Equal asserts exp == act.

internal/wsjs/wsjs_js.go

-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ func (c WebSocket) OnMessage(fn func(m MessageEvent)) (remove func()) {
119119
Data: data,
120120
}
121121
fn(me)
122-
123-
return
124122
})
125123
}
126124

netconn.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (nc *netConn) SetWriteDeadline(t time.Time) error {
200200
if t.IsZero() {
201201
nc.writeTimer.Stop()
202202
} else {
203-
nc.writeTimer.Reset(t.Sub(time.Now()))
203+
nc.writeTimer.Reset(time.Until(t))
204204
}
205205
return nil
206206
}
@@ -210,7 +210,7 @@ func (nc *netConn) SetReadDeadline(t time.Time) error {
210210
if t.IsZero() {
211211
nc.readTimer.Stop()
212212
} else {
213-
nc.readTimer.Reset(t.Sub(time.Now()))
213+
nc.readTimer.Reset(time.Until(t))
214214
}
215215
return nil
216216
}

ws_js.go

+23-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ import (
1818
"nhooyr.io/websocket/internal/xsync"
1919
)
2020

21+
// opcode represents a WebSocket opcode.
22+
type opcode int
23+
24+
// https://tools.ietf.org/html/rfc6455#section-11.8.
25+
const (
26+
opContinuation opcode = iota
27+
opText
28+
opBinary
29+
// 3 - 7 are reserved for further non-control frames.
30+
_
31+
_
32+
_
33+
_
34+
_
35+
opClose
36+
opPing
37+
opPong
38+
// 11-16 are reserved for further control frames.
39+
)
40+
2141
// Conn provides a wrapper around the browser WebSocket API.
2242
type Conn struct {
2343
ws wsjs.WebSocket
@@ -302,7 +322,7 @@ func (c *Conn) Reader(ctx context.Context) (MessageType, io.Reader, error) {
302322
// It buffers the entire message in memory and then sends it when the writer
303323
// is closed.
304324
func (c *Conn) Writer(ctx context.Context, typ MessageType) (io.WriteCloser, error) {
305-
return writer{
325+
return &writer{
306326
c: c,
307327
ctx: ctx,
308328
typ: typ,
@@ -320,7 +340,7 @@ type writer struct {
320340
b *bytes.Buffer
321341
}
322342

323-
func (w writer) Write(p []byte) (int, error) {
343+
func (w *writer) Write(p []byte) (int, error) {
324344
if w.closed {
325345
return 0, errors.New("cannot write to closed writer")
326346
}
@@ -331,7 +351,7 @@ func (w writer) Write(p []byte) (int, error) {
331351
return n, nil
332352
}
333353

334-
func (w writer) Close() error {
354+
func (w *writer) Close() error {
335355
if w.closed {
336356
return errors.New("cannot close closed writer")
337357
}

0 commit comments

Comments
 (0)