Skip to content

Commit 1bddf2e

Browse files
committed
bumps go version & removes deprecated module usage
1 parent 750bf92 commit 1bddf2e

23 files changed

+1015
-45
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
coverage.coverprofile
1+
coverage.coverprofile

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ verify: golangci-lint gosec govulncheck
3131
.PHONY: test
3232
test:
3333
@echo "##### Running tests"
34-
go test -race -cover -coverprofile=coverage.coverprofile -covermode=atomic -v ./...
34+
go test -race -cover -coverprofile=coverage.coverprofile -covermode=atomic -v ./...

client.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import (
1111
"errors"
1212
"fmt"
1313
"io"
14-
"io/ioutil"
1514
"net"
1615
"net/http"
1716
"net/http/httptrace"
1817
"net/url"
1918
"strings"
2019
"time"
20+
21+
"golang.org/x/net/proxy"
2122
)
2223

2324
// ErrBadHandshake is returned when the server response to opening handshake is
@@ -304,7 +305,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
304305
return nil, nil, err
305306
}
306307
if proxyURL != nil {
307-
dialer, err := proxy_FromURL(proxyURL, netDialerFunc(netDial))
308+
dialer, err := proxy.FromURL(proxyURL, netDialerFunc(netDial))
308309
if err != nil {
309310
return nil, nil, err
310311
}
@@ -400,7 +401,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
400401
// debugging.
401402
buf := make([]byte, 1024)
402403
n, _ := io.ReadFull(resp.Body, buf)
403-
resp.Body = ioutil.NopCloser(bytes.NewReader(buf[:n]))
404+
resp.Body = io.NopCloser(bytes.NewReader(buf[:n]))
404405
return nil, resp, ErrBadHandshake
405406
}
406407

@@ -418,7 +419,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
418419
break
419420
}
420421

421-
resp.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
422+
resp.Body = io.NopCloser(bytes.NewReader([]byte{}))
422423
conn.subprotocol = resp.Header.Get("Sec-Websocket-Protocol")
423424

424425
netConn.SetDeadline(time.Time{})
@@ -428,7 +429,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
428429

429430
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
430431
if cfg == nil {
431-
return &tls.Config{}
432+
return &tls.Config{MinVersion: tls.VersionTLS12}
432433
}
433434
return cfg.Clone()
434435
}

client_server_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"errors"
1515
"fmt"
1616
"io"
17-
"io/ioutil"
1817
"log"
1918
"net"
2019
"net/http"
@@ -564,7 +563,7 @@ func TestRespOnBadHandshake(t *testing.T) {
564563
t.Errorf("resp.StatusCode=%d, want %d", resp.StatusCode, expectedStatus)
565564
}
566565

567-
p, err := ioutil.ReadAll(resp.Body)
566+
p, err := io.ReadAll(resp.Body)
568567
if err != nil {
569568
t.Fatalf("ReadFull(resp.Body) returned error %v", err)
570569
}

compression_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"testing"
98
)
109

@@ -43,7 +42,7 @@ func textMessages(num int) [][]byte {
4342
}
4443

4544
func BenchmarkWriteNoCompression(b *testing.B) {
46-
w := ioutil.Discard
45+
w := io.Discard
4746
c := newTestConn(nil, w, false)
4847
messages := textMessages(100)
4948
b.ResetTimer()
@@ -54,7 +53,7 @@ func BenchmarkWriteNoCompression(b *testing.B) {
5453
}
5554

5655
func BenchmarkWriteWithCompression(b *testing.B) {
57-
w := ioutil.Discard
56+
w := io.Discard
5857
c := newTestConn(nil, w, false)
5958
messages := textMessages(100)
6059
c.enableWriteCompression = true

conn.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ package websocket
66

77
import (
88
"bufio"
9+
"crypto/rand"
910
"encoding/binary"
1011
"errors"
1112
"io"
12-
"io/ioutil"
13-
"math/rand"
1413
"net"
1514
"strconv"
1615
"strings"
@@ -181,16 +180,16 @@ var (
181180
errInvalidControlFrame = errors.New("websocket: invalid control frame")
182181
)
183182

184-
func newMaskKey() [4]byte {
185-
n := rand.Uint32()
186-
return [4]byte{byte(n), byte(n >> 8), byte(n >> 16), byte(n >> 24)}
187-
}
183+
// maskRand is an io.Reader for generating mask bytes. The reader is initialized
184+
// to crypto/rand Reader. Tests swap the reader to a math/rand reader for
185+
// reproducible results.
186+
var maskRand = rand.Reader
188187

189-
func hideTempErr(err error) error {
190-
if e, ok := err.(net.Error); ok && e.Temporary() {
191-
err = &netError{msg: e.Error(), timeout: e.Timeout()}
192-
}
193-
return err
188+
// newMaskKey returns a new 32 bit value for masking client frames.
189+
func newMaskKey() [4]byte {
190+
var k [4]byte
191+
_, _ = io.ReadFull(maskRand, k[:])
192+
return k
194193
}
195194

196195
func isControl(frameType int) bool {
@@ -435,9 +434,11 @@ func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) er
435434
maskBytes(key, 0, buf[6:])
436435
}
437436

438-
d := 1000 * time.Hour
439-
if !deadline.IsZero() {
440-
d = deadline.Sub(time.Now())
437+
if deadline.IsZero() {
438+
// No timeout for zero time.
439+
<-c.mu
440+
} else {
441+
d := time.Until(deadline)
441442
if d < 0 {
442443
return errWriteTimeout
443444
}
@@ -798,7 +799,7 @@ func (c *Conn) advanceFrame() (int, error) {
798799
// 1. Skip remainder of previous frame.
799800

800801
if c.readRemaining > 0 {
801-
if _, err := io.CopyN(ioutil.Discard, c.br, c.readRemaining); err != nil {
802+
if _, err := io.CopyN(io.Discard, c.br, c.readRemaining); err != nil {
802803
return noFrame, err
803804
}
804805
}
@@ -1097,7 +1098,7 @@ func (c *Conn) ReadMessage() (messageType int, p []byte, err error) {
10971098
if err != nil {
10981099
return messageType, nil, err
10991100
}
1100-
p, err = ioutil.ReadAll(r)
1101+
p, err = io.ReadAll(r)
11011102
return messageType, p, err
11021103
}
11031104

@@ -1164,7 +1165,7 @@ func (c *Conn) SetPingHandler(h func(appData string) error) {
11641165
err := c.WriteControl(PongMessage, []byte(message), time.Now().Add(writeWait))
11651166
if err == ErrCloseSent {
11661167
return nil
1167-
} else if e, ok := err.(net.Error); ok && e.Temporary() {
1168+
} else if _, ok := err.(net.Error); ok {
11681169
return nil
11691170
}
11701171
return err

conn_broadcast_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package websocket
66

77
import (
88
"io"
9-
"io/ioutil"
109
"sync/atomic"
1110
"testing"
1211
)
@@ -45,7 +44,7 @@ func newBroadcastConn(c *Conn) *broadcastConn {
4544

4645
func newBroadcastBench(usePrepared, compression bool) *broadcastBench {
4746
bench := &broadcastBench{
48-
w: ioutil.Discard,
47+
w: io.Discard,
4948
doneCh: make(chan struct{}),
5049
closeCh: make(chan struct{}),
5150
usePrepared: usePrepared,

conn_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"errors"
1111
"fmt"
1212
"io"
13-
"io/ioutil"
1413
"net"
1514
"reflect"
1615
"sync"
@@ -126,7 +125,7 @@ func TestFraming(t *testing.T) {
126125
}
127126

128127
t.Logf("frame size: %d", n)
129-
rbuf, err := ioutil.ReadAll(r)
128+
rbuf, err := io.ReadAll(r)
130129
if err != nil {
131130
t.Errorf("%s: ReadFull() returned rbuf, %v", name, err)
132131
continue
@@ -414,7 +413,7 @@ func TestCloseFrameBeforeFinalMessageFrame(t *testing.T) {
414413
if op != BinaryMessage || err != nil {
415414
t.Fatalf("NextReader() returned %d, %v", op, err)
416415
}
417-
_, err = io.Copy(ioutil.Discard, r)
416+
_, err = io.Copy(io.Discard, r)
418417
if !reflect.DeepEqual(err, expectedErr) {
419418
t.Fatalf("io.Copy() returned %v, want %v", err, expectedErr)
420419
}
@@ -449,7 +448,7 @@ func TestEOFWithinFrame(t *testing.T) {
449448
if op != BinaryMessage || err != nil {
450449
t.Fatalf("%d: NextReader() returned %d, %v", n, op, err)
451450
}
452-
_, err = io.Copy(ioutil.Discard, r)
451+
_, err = io.Copy(io.Discard, r)
453452
if err != errUnexpectedEOF {
454453
t.Fatalf("%d: io.Copy() returned %v, want %v", n, err, errUnexpectedEOF)
455454
}
@@ -475,7 +474,7 @@ func TestEOFBeforeFinalFrame(t *testing.T) {
475474
if op != BinaryMessage || err != nil {
476475
t.Fatalf("NextReader() returned %d, %v", op, err)
477476
}
478-
_, err = io.Copy(ioutil.Discard, r)
477+
_, err = io.Copy(io.Discard, r)
479478
if err != errUnexpectedEOF {
480479
t.Fatalf("io.Copy() returned %v, want %v", err, errUnexpectedEOF)
481480
}
@@ -562,7 +561,7 @@ func TestReadLimit(t *testing.T) {
562561
if op != BinaryMessage || err != nil {
563562
t.Fatalf("2: NextReader() returned %d, %v", op, err)
564563
}
565-
_, err = io.Copy(ioutil.Discard, r)
564+
_, err = io.Copy(io.Discard, r)
566565
if err != ErrReadLimit {
567566
t.Fatalf("io.Copy() returned %v", err)
568567
}

examples/filewatch/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ package main
77
import (
88
"flag"
99
"html/template"
10-
"io/ioutil"
1110
"log"
1211
"net/http"
1312
"os"
13+
"path/filepath"
1414
"strconv"
1515
"time"
1616

@@ -49,7 +49,7 @@ func readFileIfModified(lastMod time.Time) ([]byte, time.Time, error) {
4949
if !fi.ModTime().After(lastMod) {
5050
return nil, lastMod, nil
5151
}
52-
p, err := ioutil.ReadFile(filename)
52+
p, err := os.ReadFile(filepath.Clean(filename))
5353
if err != nil {
5454
return nil, fi.ModTime(), err
5555
}

go.mod

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/gorilla/websocket
22

3-
go 1.12
3+
go 1.20
4+
5+
require golang.org/x/net v0.23.0

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
2+
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=

proxy.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"net/http"
1313
"net/url"
1414
"strings"
15+
16+
"golang.org/x/net/proxy"
1517
)
1618

1719
type netDialerFunc func(network, addr string) (net.Conn, error)
@@ -21,7 +23,7 @@ func (fn netDialerFunc) Dial(network, addr string) (net.Conn, error) {
2123
}
2224

2325
func init() {
24-
proxy_RegisterDialerType("http", func(proxyURL *url.URL, forwardDialer proxy_Dialer) (proxy_Dialer, error) {
26+
proxy.RegisterDialerType("http", func(proxyURL *url.URL, forwardDialer proxy.Dialer) (proxy.Dialer, error) {
2527
return &httpProxyDialer{proxyURL: proxyURL, forwardDial: forwardDialer.Dial}, nil
2628
})
2729
}
@@ -68,7 +70,7 @@ func (hpd *httpProxyDialer) Dial(network string, addr string) (net.Conn, error)
6870
return nil, err
6971
}
7072

71-
if resp.StatusCode != 200 {
73+
if resp.StatusCode != http.StatusOK {
7274
conn.Close()
7375
f := strings.SplitN(resp.Status, " ", 2)
7476
return nil, errors.New(f[1])

tls_handshake.go

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//go:build go1.17
2-
// +build go1.17
3-
41
package websocket
52

63
import (

vendor/golang.org/x/net/LICENSE

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/net/PATENTS

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)