npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

is-websocket-handshake

1.0.0

@watson

npmHomeRepoSnykSocket
Downloads:2
$ npm install is-websocket-handshake
DailyWeeklyMonthlyYearly

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