Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed May 16, 2024
1 parent ef8e1e0 commit b50e9d9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/web/websocket/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function establishWebSocketConnection (url, protocols, client, ws, onEstablish,
// 9. Let permessageDeflate be a user-agent defined
// "permessage-deflate" extension header value.
// https://github.com/mozilla/gecko-dev/blob/ce78234f5e653a5d3916813ff990f053510227bc/netwerk/protocol/websocket/WebSocketChannel.cpp#L2673
const permessageDeflate = 'permessage-deflate'
const permessageDeflate = options.node?.['client-extensions'] ?? ''

// 10. Append (`Sec-WebSocket-Extensions`, permessageDeflate) to
// request’s header list.
Expand Down
15 changes: 14 additions & 1 deletion lib/web/websocket/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,14 @@ webidl.converters['DOMString or sequence<DOMString>'] = function (V, prefix, arg
return webidl.converters.DOMString(V, prefix, argument)
}

webidl.converters.WebSocketInitNodeOptions = webidl.dictionaryConverter([
{
key: 'client-extensions',
converter: webidl.converters.DOMString,
defaultValue: () => ''
}
])

// This implements the proposal made in https://github.com/whatwg/websockets/issues/42
webidl.converters.WebSocketInit = webidl.dictionaryConverter([
{
Expand All @@ -558,12 +566,17 @@ webidl.converters.WebSocketInit = webidl.dictionaryConverter([
},
{
key: 'dispatcher',
converter: (V) => V,
converter: webidl.converters.any,
defaultValue: () => getGlobalDispatcher()
},
{
key: 'headers',
converter: webidl.nullableConverter(webidl.converters.HeadersInit)
},
{
key: 'node',
converter: webidl.converters.WebSocketInitNodeOptions,
defaultValue: () => ({})
}
])

Expand Down
12 changes: 9 additions & 3 deletions test/autobahn/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@ let currentTest = 1
let testCount

const autobahnFuzzingserverUrl = process.env.FUZZING_SERVER_URL || 'ws://localhost:9001'
const options = {
node: {
'client-extensions': 'permessage-deflate'
}
}

function nextTest () {
let ws

if (currentTest > testCount) {
ws = new WebSocket(`${autobahnFuzzingserverUrl}/updateReports?agent=undici`)
ws = new WebSocket(`${autobahnFuzzingserverUrl}/updateReports?agent=undici`, options)
return
}

console.log(`Running test case ${currentTest}/${testCount}`)

ws = new WebSocket(
`${autobahnFuzzingserverUrl}/runCase?case=${currentTest}&agent=undici`
`${autobahnFuzzingserverUrl}/runCase?case=${currentTest}&agent=undici`,
options
)
ws.addEventListener('message', (data) => {
ws.send(data.data)
Expand All @@ -32,7 +38,7 @@ function nextTest () {
})
}

const ws = new WebSocket(`${autobahnFuzzingserverUrl}/getCaseCount`)
const ws = new WebSocket(`${autobahnFuzzingserverUrl}/getCaseCount`, options)
ws.addEventListener('message', (data) => {
testCount = parseInt(data.data)
})
Expand Down

0 comments on commit b50e9d9

Please sign in to comment.