Skip to content

Commit e605c73

Browse files
bbrksgregns1
authored andcommitted
CBG-1901: Update ISGR/Blip to nhooyr.io/websocket (#5421)
* Update ISGR/Blip to nhooyr.io/websocket * Fix manifest path * Update manifest for couchbasedeps compress * Bump go-blip manifest
1 parent ca865ab commit e605c73

File tree

4 files changed

+22
-33
lines changed

4 files changed

+22
-33
lines changed

db/active_replicator.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ package db
1212

1313
import (
1414
"context"
15-
"crypto/tls"
1615
"encoding/base64"
1716
"errors"
1817
"fmt"
@@ -21,7 +20,6 @@ import (
2120

2221
"github.com/couchbase/go-blip"
2322
"github.com/couchbase/sync_gateway/base"
24-
"golang.org/x/net/websocket"
2523
)
2624

2725
// ActiveReplicator is a wrapper to encapsulate separate push and pull active replicators.
@@ -263,23 +261,18 @@ func blipSync(target url.URL, blipContext *blip.Context, insecureSkipVerify bool
263261
target.User = nil
264262
}
265263

266-
config, err := websocket.NewConfig(target.String()+"/_blipsync?"+BLIPSyncClientTypeQueryParam+"="+string(BLIPClientTypeSGR2), "http://localhost")
267-
if err != nil {
268-
return nil, err
269-
}
270-
271-
if insecureSkipVerify {
272-
if config.TlsConfig == nil {
273-
config.TlsConfig = new(tls.Config)
274-
}
275-
config.TlsConfig.InsecureSkipVerify = true
264+
config := blip.DialOptions{
265+
URL: target.String() + "/_blipsync?" + BLIPSyncClientTypeQueryParam + "=" + string(BLIPClientTypeSGR2),
266+
HTTPClient: client,
276267
}
277268

278269
if basicAuthCreds != nil {
279-
config.Header.Add("Authorization", "Basic "+base64UserInfo(basicAuthCreds))
270+
config.HTTPHeader = http.Header{
271+
"Authorization": []string{"Basic " + base64UserInfo(basicAuthCreds)},
272+
}
280273
}
281274

282-
return blipContext.DialConfig(config)
275+
return blipContext.DialConfig(&config)
283276
}
284277

285278
// base64UserInfo returns the base64 encoded version of the given UserInfo.

manifest/default.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ licenses/APL2.txt.
105105

106106
<project name="goutils" path="godeps/src/github.com/couchbase/goutils" remote="couchbase" revision="f98adca8eb365032cab838ef4d99453931afa112"/>
107107

108-
<project name="go-blip" path="godeps/src/github.com/couchbase/go-blip" remote="couchbase" revision="3c4edeb16c47cdb3bcd1eeab3b3c5c87832d4923"/>
108+
<project name="go-blip" path="godeps/src/github.com/couchbase/go-blip" remote="couchbase" revision="746a6c2c23026766d1a3ace9cca85c5a01f11408"/>
109109

110110
<project name="errors" path="godeps/src/github.com/pkg/errors" remote="couchbasedeps" revision="f15c970de5b76fac0b59abb32d62c17cc7bed265"/>
111111

rest/blip_sync.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919

2020
"github.com/couchbase/go-blip"
2121
"github.com/couchbase/sync_gateway/base"
22-
"golang.org/x/net/websocket"
2322
)
2423

2524
// HTTP handler for incoming BLIP sync WebSocket request (/db/_blipsync)
@@ -61,16 +60,17 @@ func (h *handler) handleBLIPSync() error {
6160

6261
// Create a BLIP WebSocket handler and have it handle the request:
6362
server := blipContext.WebSocketServer()
64-
defaultHandler := server.Handler
65-
server.Handler = func(conn *websocket.Conn) {
66-
h.logStatus(http.StatusSwitchingProtocols, fmt.Sprintf("[%s] Upgraded to WebSocket protocol %s+%s%s", blipContext.ID, blip.WebSocketSubProtocolPrefix, blipContext.ActiveSubprotocol(), h.formattedEffectiveUserName()))
67-
defer func() {
68-
_ = conn.Close() // in case it wasn't closed already
69-
base.InfofCtx(h.db.Ctx, base.KeyHTTP, "%s: --> BLIP+WebSocket connection closed", h.formatSerialNumber())
70-
}()
71-
defaultHandler(conn)
63+
64+
middleware := func(next http.Handler) http.Handler {
65+
return http.HandlerFunc(
66+
func(w http.ResponseWriter, r *http.Request) {
67+
h.logStatus(http.StatusSwitchingProtocols, fmt.Sprintf("[%s] Upgraded to WebSocket protocol %s+%s%s", blipContext.ID, blip.WebSocketSubProtocolPrefix, blipContext.ActiveSubprotocol(), h.formattedEffectiveUserName()))
68+
defer base.InfofCtx(h.db.Ctx, base.KeyHTTP, "%s: --> BLIP+WebSocket connection closed", h.formatSerialNumber())
69+
next.ServeHTTP(w, r)
70+
})
7271
}
7372

74-
server.ServeHTTP(h.response, h.rq)
73+
middleware(server).ServeHTTP(h.response, h.rq)
74+
7575
return nil
7676
}

rest/utilities_testing.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"github.com/stretchr/testify/assert"
3737
"github.com/stretchr/testify/require"
3838
"golang.org/x/crypto/bcrypt"
39-
"golang.org/x/net/websocket"
4039
)
4140

4241
// Testing utilities that have been included in the rest package so that they
@@ -993,20 +992,17 @@ func createBlipTesterWithSpec(tb testing.TB, spec BlipTesterSpec, rt *RestTester
993992
return nil, err
994993
}
995994

996-
origin := "http://localhost" // TODO: what should be used here?
997-
998-
config, err := websocket.NewConfig(u.String(), origin)
999-
if err != nil {
1000-
return nil, err
995+
config := blip.DialOptions{
996+
URL: u.String(),
1001997
}
1002998

1003999
if len(spec.connectingUsername) > 0 {
1004-
config.Header = http.Header{
1000+
config.HTTPHeader = http.Header{
10051001
"Authorization": {"Basic " + base64.StdEncoding.EncodeToString([]byte(spec.connectingUsername+":"+spec.connectingPassword))},
10061002
}
10071003
}
10081004

1009-
bt.sender, err = bt.blipContext.DialConfig(config)
1005+
bt.sender, err = bt.blipContext.DialConfig(&config)
10101006
if err != nil {
10111007
return nil, err
10121008
}

0 commit comments

Comments
 (0)