diff --git a/websockets/websockets.go b/websockets/websockets.go index 4448eea..7517e4d 100644 --- a/websockets/websockets.go +++ b/websockets/websockets.go @@ -85,6 +85,7 @@ type webSocket struct { bufferedAmount int binaryType string protocol string + extensions []string } type ping struct { @@ -193,7 +194,8 @@ func defineWebsocket(rt *goja.Runtime, w *webSocket) { must(rt, w.obj.DefineAccessorProperty( "bufferedAmount", rt.ToValue(func() goja.Value { return rt.ToValue(w.bufferedAmount) }), nil, goja.FLAG_FALSE, goja.FLAG_TRUE)) - // extensions + must(rt, w.obj.DefineAccessorProperty("extensions", + rt.ToValue(func() goja.Value { return rt.ToValue(w.extensions) }), nil, goja.FLAG_FALSE, goja.FLAG_TRUE)) must(rt, w.obj.DefineAccessorProperty( "protocol", rt.ToValue(func() goja.Value { return rt.ToValue(w.protocol) }), nil, goja.FLAG_FALSE, goja.FLAG_TRUE)) must(rt, w.obj.DefineAccessorProperty( @@ -304,6 +306,7 @@ func (w *webSocket) establishConnection(params *wsParams) { if conn != nil { w.protocol = conn.Subprotocol() } + w.extensions = httpResponse.Header.Values("Sec-WebSocket-Extensions") w.tagsAndMeta.SetSystemTagOrMetaIfEnabled(systemTags, metrics.TagSubproto, w.protocol) } w.conn = conn diff --git a/websockets/websockets_test.go b/websockets/websockets_test.go index f2097bf..9ebe6a2 100644 --- a/websockets/websockets_test.go +++ b/websockets/websockets_test.go @@ -1096,6 +1096,11 @@ func TestCompressionSession(t *testing.T) { throw new Error("wrong message received from server: ", event.data) } + const expectedExtension = "permessage-deflate; server_no_context_takeover; client_no_context_takeover" + if (!(ws.extensions.includes(expectedExtension))) { + throw "expected value '" + expectedExtension + "' missing in " + JSON.stringify(ws.extensions); + } + ws.close() }