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: 3 months 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 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-16T13:50:39.000Z (over 8 years ago)
- Last Synced: 2025-03-26T01:41:25.779Z (4 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 5
- Watchers: 2
- 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.
[](https://travis-ci.org/watson/is-websocket-handshake)
[](https://github.com/feross/standard)
[](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