This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http') | |
const crypto = require('crypto') | |
const server = http.createServer((req, res) => { | |
console.log('got request', req.url) | |
res.writeHead(200, { 'Content-Type': 'text/plain' }) | |
res.end('okay') | |
}) | |
server.on('upgrade', function (req, socket) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var buffer = require('buffer'); | |
var path = require('path'); | |
var fs = require('fs'); | |
function encode_base64(filename){ | |
fs.readFile(path.join(__dirname,'/public/',filename),function(error,data){ | |
if(error){ | |
throw error; | |
}else{ | |
var buf = Buffer.from(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl --include \ | |
--no-buffer \ | |
--header "Connection: Upgrade" \ | |
--header "Upgrade: websocket" \ | |
--header "Host: example.com:80" \ | |
--header "Origin: http://example.com:80" \ | |
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \ | |
--header "Sec-WebSocket-Version: 13" \ | |
http://example.com:80/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @credit: http://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer | |
// From Buffer to ArrayBuffer: | |
function toArrayBuffer(buffer) { | |
var ab = new ArrayBuffer(buffer.length); | |
var view = new Uint8Array(ab); | |
for (var i = 0; i < buffer.length; ++i) { | |
view[i] = buffer[i]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require('crypto'); | |
function sha1( data ) { | |
var generator = crypto.createHash('sha1'); | |
generator.update( data ) | |
return generator.digest('hex') | |
} | |
console.log( sha1('adrian') ) |