is-websocket-handshake

    1.0.0 • Public • Published

    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

    Install

    npm i is-websocket-handshake

    DownloadsWeekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • watson