1.0.0 • Published 7 years ago

is-websocket-handshake v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

is-websocket-handshake

Check if a request is a WebSocket handshake request.

Build status js-standard-style sponsor

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