Skip to content

Commit 0028022

Browse files
authored
perf(index): cache status code regex
Signed-off-by: Frazer Smith <[email protected]>
1 parent 035a3c7 commit 0028022

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const Duplexify = require('duplexify')
99

1010
const kWs = Symbol('ws-socket')
1111
const kWsHead = Symbol('ws-head')
12+
const statusCodeReg = /HTTP\/1.1 (\d+)/u
1213

1314
function fastifyWebsocket (fastify, opts, next) {
1415
fastify.decorateRequest('ws', null)
@@ -74,7 +75,7 @@ function fastifyWebsocket (fastify, opts, next) {
7475
ws.setSocket(clientStream, head, { maxPayload: 0 })
7576
} else {
7677
clientStream.removeListener('data', onData)
77-
const statusCode = Number(chunk.toString().match(/HTTP\/1.1 (\d+)/)[1])
78+
const statusCode = Number(statusCodeReg.exec(chunk.toString())[1])
7879
reject(new Error('Unexpected server response: ' + statusCode))
7980
}
8081
}

0 commit comments

Comments
 (0)