https://github.com/vutran/websocket-handshake
Simple utility to generate a websocket handshake hash/response.
https://github.com/vutran/websocket-handshake
handshake javascript node websocket
Last synced: 4 months ago
JSON representation
Simple utility to generate a websocket handshake hash/response.
- Host: GitHub
- URL: https://github.com/vutran/websocket-handshake
- Owner: vutran
- License: mit
- Created: 2016-08-21T18:10:52.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-21T18:20:31.000Z (about 9 years ago)
- Last Synced: 2025-05-07T09:06:07.399Z (5 months ago)
- Topics: handshake, javascript, node, websocket
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# websocket-handshake
> Simple utility to generate a websocket handshake hash/response.
## Install
```bash
$ npm install --save websocket-handshake
```## Usage
Import the module
```js
const { getResponseHash, getResponseHeaders } = require('websocket-handshake');
```Create the handshake response hash
```js
const hash = getResponseHash('dGhlIHNhbXBsZSBub25jZQ==');
// => s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
```Create the handshake response headers
```js
const request = { ... }; // instance of http.ServerRequest
const headers = getResponseHeaders(request);
// => HTTP/1.1 101 Switching Protocols
// Upgrade: websocket
// Connection: Upgrade
// Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
```## License
MIT © [Vu Tran](https://github.com/vutran/)