is-websocket-handshake
v1.0.0
Published
Check if a request is a WebSocket handshake request
Downloads
8
Maintainers
Readme
is-websocket-handshake
Check if a request is a WebSocket handshake request.
Example WebSocket handshake:
GET /chat HTTP/1.1
Host: example.com:8000
Upgrade: websocket
Connection: Upgrade
Installation
npm install is-websocket-handshake --save
Usage
var http = require('http')
var isWebSocketHandshake = require('is-websocket-handshake')
var server = http.createServer(function (req, res) {
console.log('received regular http request')
})
server.on('upgrade', function (req, socket, head) {
if (isWebSocketHandshake(req)) {
console.log('received proper WebSocket handshake')
}
})
http.listen(3000)
API
isWebSocketHandshake(request)
Accepts an instance of a http.IncomingMessage
object
as the first argument.
Returns a boolean.
Acknowledgements
This project was kindly sponsored by Opbeat.
License
MIT