Skip to content

Commit 1b95e2e

Browse files
authored
copy websocket package from centrifuge (#1005)
1 parent dbbc23b commit 1b95e2e

30 files changed

+5111
-10
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ updates:
55
schedule:
66
interval: monthly
77
ignore:
8-
- dependency-name: github.com/gorilla/websocket # v1.5.1 breaks
9-
- dependency-name: github.com/centrifugal/centrifuge # updates manually
8+
- dependency-name: github.com/centrifugal/centrifuge # updating manually.
109
groups:
1110
go-packages:
1211
patterns:

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ require (
2121
github.com/gobwas/glob v0.2.3
2222
github.com/google/uuid v1.6.0
2323
github.com/gorilla/securecookie v1.1.2
24-
github.com/gorilla/websocket v1.5.3
2524
github.com/hashicorp/go-envparse v0.1.0
2625
github.com/jackc/pgx/v5 v5.7.5
2726
github.com/joho/godotenv v1.5.1

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ github.com/googleapis/gax-go/v2 v2.14.2 h1:eBLnkZ9635krYIPD+ag1USrOAI0Nr0QYF3+/3
162162
github.com/googleapis/gax-go/v2 v2.14.2/go.mod h1:ON64QhlJkhVtSqp4v1uaK92VyZ2gmvDQsweuyLV+8+w=
163163
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
164164
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
165-
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
166-
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
167165
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 h1:X5VWvz21y3gzm9Nw/kaUeku/1+uBhcekkmy4IkffJww=
168166
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1/go.mod h1:Zanoh4+gvIgluNqcfMVTJueD4wSS5hT7zTt4Mrutd90=
169167
github.com/hashicorp/go-envparse v0.1.0 h1:bE++6bhIsNCPLvgDZkYqo3nA+/PFI51pkrHdmPSDFPY=

internal/uniws/handler.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"time"
88

99
"github.com/centrifugal/centrifugo/v6/internal/logging"
10+
"github.com/centrifugal/centrifugo/v6/internal/websocket"
1011

1112
"github.com/centrifugal/centrifuge"
1213
"github.com/centrifugal/protocol"
13-
"github.com/gorilla/websocket"
1414
"github.com/rs/zerolog/log"
1515
)
1616

@@ -72,7 +72,7 @@ func (s *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
7272
compressionLevel := s.config.CompressionLevel
7373
compressionMinSize := s.config.CompressionMinSize
7474

75-
conn, err := s.upgrade.Upgrade(rw, r, nil)
75+
conn, _, err := s.upgrade.Upgrade(rw, r, nil)
7676
if err != nil {
7777
log.Error().Err(err).Str("transport", transportName).Msg("websocket upgrade error")
7878
return
@@ -104,7 +104,7 @@ func (s *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
104104
if pingInterval > 0 {
105105
pongWait := pingInterval * 10 / 9
106106
_ = conn.SetReadDeadline(time.Now().Add(pongWait))
107-
conn.SetPongHandler(func(string) error {
107+
conn.SetPongHandler(func([]byte) error {
108108
_ = conn.SetReadDeadline(time.Now().Add(pongWait))
109109
return nil
110110
})
@@ -189,7 +189,6 @@ func (s *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
189189
// https://github.com/gorilla/websocket/issues/448
190190
conn.SetPingHandler(nil)
191191
conn.SetPongHandler(nil)
192-
conn.SetCloseHandler(nil)
193192
_ = conn.SetReadDeadline(time.Now().Add(closeFrameWait))
194193
for {
195194
if _, _, err := conn.NextReader(); err != nil {

internal/uniws/transport.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"sync"
55
"time"
66

7+
"github.com/centrifugal/centrifugo/v6/internal/websocket"
8+
79
"github.com/centrifugal/centrifuge"
810
"github.com/centrifugal/protocol"
9-
"github.com/gorilla/websocket"
1011
)
1112

1213
// websocketTransport is a wrapper struct over websocket connection to fit session

internal/websocket/AUTHORS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This is the official list of Gorilla WebSocket authors for copyright
2+
# purposes.
3+
#
4+
# Please keep the list sorted.
5+
6+
Gary Burd <[email protected]>
7+
Google LLC (https://opensource.google.com/)
8+
Joachim Bauch <[email protected]>

internal/websocket/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2013 The Gorilla WebSocket Authors. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are met:
5+
6+
Redistributions of source code must retain the above copyright notice, this
7+
list of conditions and the following disclaimer.
8+
9+
Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
17+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

internal/websocket/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Fork of Gorilla Websocket adapted for Centrifuge needs. All copyrights were left – huge respect to the original authors.
2+
3+
What was changed:
4+
5+
* no custom Proxy in Client
6+
* no concurrent use best-effort detection
7+
* selected subprotocol is not kept internally, returned during Upgrade or Dial
8+
* lint fixes
9+
* no possibility to set custom CloseHandler
10+
* upgrade optimizations (9 -> 3 allocations, see BenchmarkUpgrade)

0 commit comments

Comments
 (0)