Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/watson/is-websocket-handshake
Check if a request is a WebSocket handshake request
https://github.com/watson/is-websocket-handshake
Last synced: 2 days ago
JSON representation
Check if a request is a WebSocket handshake request
- Host: GitHub
- URL: https://github.com/watson/is-websocket-handshake
- Owner: watson
- License: mit
- Created: 2017-01-16T13:36:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-01-16T13:50:39.000Z (over 7 years ago)
- Last Synced: 2024-09-25T21:35:52.318Z (6 days ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# is-websocket-handshake
Check if a request is a WebSocket handshake request.
[![Build status](https://travis-ci.org/watson/is-websocket-handshake.svg?branch=master)](https://travis-ci.org/watson/is-websocket-handshake)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
[![sponsor](https://img.shields.io/badge/sponsored%20by-Opbeat-3360A3.svg)](https://opbeat.com)Example WebSocket handshake:
```http
GET /chat HTTP/1.1
Host: example.com:8000
Upgrade: websocket
Connection: Upgrade
```## Installation
```
npm install is-websocket-handshake --save
```## Usage
```js
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](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
as the first argument.Returns a boolean.
## Acknowledgements
This project was kindly sponsored by [Opbeat](https://opbeat.com).
## License
MIT