dragonfly_chrome_headless 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dragonfly_chrome_headless.gemspec +27 -0
- data/lib/dragonfly_chrome_headless.rb +9 -0
- data/lib/dragonfly_chrome_headless/plugin.rb +17 -0
- data/lib/dragonfly_chrome_headless/processors/rasterize.rb +33 -0
- data/lib/dragonfly_chrome_headless/version.rb +3 -0
- data/node_modules/.bin/chrome-remote-interface +1 -0
- data/node_modules/.bin/mkdirp +1 -0
- data/node_modules/.bin/rimraf +1 -0
- data/node_modules/@types/core-js/LICENSE +21 -0
- data/node_modules/@types/core-js/README.md +16 -0
- data/node_modules/@types/core-js/index.d.ts +2452 -0
- data/node_modules/@types/core-js/package.json +85 -0
- data/node_modules/@types/mkdirp/README.md +18 -0
- data/node_modules/@types/mkdirp/index.d.ts +14 -0
- data/node_modules/@types/mkdirp/package.json +77 -0
- data/node_modules/@types/mkdirp/types-metadata.json +25 -0
- data/node_modules/@types/node/README.md +16 -0
- data/node_modules/@types/node/index.d.ts +4132 -0
- data/node_modules/@types/node/package.json +84 -0
- data/node_modules/balanced-match/.npmignore +5 -0
- data/node_modules/balanced-match/LICENSE.md +21 -0
- data/node_modules/balanced-match/README.md +91 -0
- data/node_modules/balanced-match/index.js +59 -0
- data/node_modules/balanced-match/package.json +112 -0
- data/node_modules/brace-expansion/README.md +123 -0
- data/node_modules/brace-expansion/index.js +201 -0
- data/node_modules/brace-expansion/package.json +114 -0
- data/node_modules/chrome-launcher/.clang-format +6 -0
- data/node_modules/chrome-launcher/.npmignore +11 -0
- data/node_modules/chrome-launcher/README.md +123 -0
- data/node_modules/chrome-launcher/ask.js +32 -0
- data/node_modules/chrome-launcher/ask.ts +35 -0
- data/node_modules/chrome-launcher/chrome-finder.js +157 -0
- data/node_modules/chrome-launcher/chrome-finder.ts +186 -0
- data/node_modules/chrome-launcher/chrome-launcher.js +245 -0
- data/node_modules/chrome-launcher/chrome-launcher.ts +312 -0
- data/node_modules/chrome-launcher/compiled-check.js +14 -0
- data/node_modules/chrome-launcher/flags.js +27 -0
- data/node_modules/chrome-launcher/flags.ts +26 -0
- data/node_modules/chrome-launcher/index.js +7 -0
- data/node_modules/chrome-launcher/index.ts +1 -0
- data/node_modules/chrome-launcher/manual-chrome-launcher.js +30 -0
- data/node_modules/chrome-launcher/package.json +116 -0
- data/node_modules/chrome-launcher/random-port.js +24 -0
- data/node_modules/chrome-launcher/random-port.ts +23 -0
- data/node_modules/chrome-launcher/tsconfig.json +19 -0
- data/node_modules/chrome-launcher/utils.js +52 -0
- data/node_modules/chrome-launcher/utils.ts +44 -0
- data/node_modules/chrome-launcher/yarn.lock +1486 -0
- data/node_modules/chrome-remote-interface/LICENSE +18 -0
- data/node_modules/chrome-remote-interface/README.md +849 -0
- data/node_modules/chrome-remote-interface/bin/client.js +337 -0
- data/node_modules/chrome-remote-interface/chrome-remote-interface.js +11 -0
- data/node_modules/chrome-remote-interface/index.js +39 -0
- data/node_modules/chrome-remote-interface/lib/api.js +84 -0
- data/node_modules/chrome-remote-interface/lib/chrome.js +307 -0
- data/node_modules/chrome-remote-interface/lib/defaults.js +4 -0
- data/node_modules/chrome-remote-interface/lib/devtools.js +245 -0
- data/node_modules/chrome-remote-interface/lib/external-request.js +28 -0
- data/node_modules/chrome-remote-interface/lib/protocol.json +13780 -0
- data/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +32 -0
- data/node_modules/chrome-remote-interface/package.json +128 -0
- data/node_modules/chrome-remote-interface/webpack.config.js +55 -0
- data/node_modules/commander/Readme.md +195 -0
- data/node_modules/commander/index.js +851 -0
- data/node_modules/commander/package.json +92 -0
- data/node_modules/concat-map/.travis.yml +4 -0
- data/node_modules/concat-map/LICENSE +18 -0
- data/node_modules/concat-map/README.markdown +62 -0
- data/node_modules/concat-map/example/map.js +6 -0
- data/node_modules/concat-map/index.js +13 -0
- data/node_modules/concat-map/package.json +117 -0
- data/node_modules/concat-map/test/map.js +39 -0
- data/node_modules/debug/.coveralls.yml +1 -0
- data/node_modules/debug/.eslintrc +11 -0
- data/node_modules/debug/.npmignore +9 -0
- data/node_modules/debug/.travis.yml +14 -0
- data/node_modules/debug/CHANGELOG.md +357 -0
- data/node_modules/debug/LICENSE +19 -0
- data/node_modules/debug/Makefile +50 -0
- data/node_modules/debug/Readme.md +312 -0
- data/node_modules/debug/component.json +19 -0
- data/node_modules/debug/karma.conf.js +70 -0
- data/node_modules/debug/node.js +1 -0
- data/node_modules/debug/package.json +124 -0
- data/node_modules/debug/src/browser.js +185 -0
- data/node_modules/debug/src/debug.js +202 -0
- data/node_modules/debug/src/index.js +10 -0
- data/node_modules/debug/src/node.js +246 -0
- data/node_modules/fs.realpath/LICENSE +43 -0
- data/node_modules/fs.realpath/README.md +33 -0
- data/node_modules/fs.realpath/index.js +66 -0
- data/node_modules/fs.realpath/old.js +303 -0
- data/node_modules/fs.realpath/package.json +94 -0
- data/node_modules/glob/LICENSE +15 -0
- data/node_modules/glob/README.md +368 -0
- data/node_modules/glob/changelog.md +67 -0
- data/node_modules/glob/common.js +240 -0
- data/node_modules/glob/glob.js +790 -0
- data/node_modules/glob/package.json +112 -0
- data/node_modules/glob/sync.js +486 -0
- data/node_modules/html-pdf-chrome/.npmignore +9 -0
- data/node_modules/html-pdf-chrome/LICENSE +21 -0
- data/node_modules/html-pdf-chrome/README.md +165 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.d.ts +87 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js +4 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.d.ts +120 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js +206 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.d.ts +70 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.js +98 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/index.d.ts +72 -0
- data/node_modules/html-pdf-chrome/lib/src/index.js +123 -0
- data/node_modules/html-pdf-chrome/lib/src/index.js.map +1 -0
- data/node_modules/html-pdf-chrome/package.json +133 -0
- data/node_modules/html-pdf-chrome/src/ChromePrintOptions.ts +99 -0
- data/node_modules/html-pdf-chrome/src/CompletionTrigger.ts +201 -0
- data/node_modules/html-pdf-chrome/src/CreateResult.ts +100 -0
- data/node_modules/html-pdf-chrome/src/index.ts +179 -0
- data/node_modules/inflight/LICENSE +15 -0
- data/node_modules/inflight/README.md +37 -0
- data/node_modules/inflight/inflight.js +54 -0
- data/node_modules/inflight/package.json +105 -0
- data/node_modules/inherits/LICENSE +16 -0
- data/node_modules/inherits/README.md +42 -0
- data/node_modules/inherits/inherits.js +7 -0
- data/node_modules/inherits/inherits_browser.js +23 -0
- data/node_modules/inherits/package.json +97 -0
- data/node_modules/lighthouse-logger/README.md +4 -0
- data/node_modules/lighthouse-logger/index.js +212 -0
- data/node_modules/lighthouse-logger/package.json +69 -0
- data/node_modules/lighthouse-logger/yarn.lock +13 -0
- data/node_modules/minimatch/LICENSE +15 -0
- data/node_modules/minimatch/README.md +209 -0
- data/node_modules/minimatch/minimatch.js +923 -0
- data/node_modules/minimatch/package.json +99 -0
- data/node_modules/minimist/.travis.yml +4 -0
- data/node_modules/minimist/LICENSE +18 -0
- data/node_modules/minimist/example/parse.js +2 -0
- data/node_modules/minimist/index.js +187 -0
- data/node_modules/minimist/package.json +101 -0
- data/node_modules/minimist/readme.markdown +73 -0
- data/node_modules/minimist/test/dash.js +24 -0
- data/node_modules/minimist/test/default_bool.js +20 -0
- data/node_modules/minimist/test/dotted.js +16 -0
- data/node_modules/minimist/test/long.js +31 -0
- data/node_modules/minimist/test/parse.js +318 -0
- data/node_modules/minimist/test/parse_modified.js +9 -0
- data/node_modules/minimist/test/short.js +67 -0
- data/node_modules/minimist/test/whitespace.js +8 -0
- data/node_modules/mkdirp/.travis.yml +8 -0
- data/node_modules/mkdirp/LICENSE +21 -0
- data/node_modules/mkdirp/bin/cmd.js +33 -0
- data/node_modules/mkdirp/bin/usage.txt +12 -0
- data/node_modules/mkdirp/examples/pow.js +6 -0
- data/node_modules/mkdirp/index.js +98 -0
- data/node_modules/mkdirp/package.json +93 -0
- data/node_modules/mkdirp/readme.markdown +100 -0
- data/node_modules/mkdirp/test/chmod.js +41 -0
- data/node_modules/mkdirp/test/clobber.js +38 -0
- data/node_modules/mkdirp/test/mkdirp.js +28 -0
- data/node_modules/mkdirp/test/opts_fs.js +29 -0
- data/node_modules/mkdirp/test/opts_fs_sync.js +27 -0
- data/node_modules/mkdirp/test/perm.js +32 -0
- data/node_modules/mkdirp/test/perm_sync.js +36 -0
- data/node_modules/mkdirp/test/race.js +37 -0
- data/node_modules/mkdirp/test/rel.js +32 -0
- data/node_modules/mkdirp/test/return.js +25 -0
- data/node_modules/mkdirp/test/return_sync.js +24 -0
- data/node_modules/mkdirp/test/root.js +19 -0
- data/node_modules/mkdirp/test/sync.js +32 -0
- data/node_modules/mkdirp/test/umask.js +28 -0
- data/node_modules/mkdirp/test/umask_sync.js +32 -0
- data/node_modules/ms/README.md +51 -0
- data/node_modules/ms/index.js +152 -0
- data/node_modules/ms/license.md +21 -0
- data/node_modules/ms/package.json +109 -0
- data/node_modules/once/LICENSE +15 -0
- data/node_modules/once/README.md +79 -0
- data/node_modules/once/once.js +42 -0
- data/node_modules/once/package.json +101 -0
- data/node_modules/path-is-absolute/index.js +20 -0
- data/node_modules/path-is-absolute/license +21 -0
- data/node_modules/path-is-absolute/package.json +111 -0
- data/node_modules/path-is-absolute/readme.md +59 -0
- data/node_modules/rimraf/LICENSE +15 -0
- data/node_modules/rimraf/README.md +101 -0
- data/node_modules/rimraf/bin.js +50 -0
- data/node_modules/rimraf/package.json +99 -0
- data/node_modules/rimraf/rimraf.js +363 -0
- data/node_modules/ultron/LICENSE +22 -0
- data/node_modules/ultron/index.js +138 -0
- data/node_modules/ultron/package.json +112 -0
- data/node_modules/wrappy/LICENSE +15 -0
- data/node_modules/wrappy/README.md +36 -0
- data/node_modules/wrappy/package.json +97 -0
- data/node_modules/wrappy/wrappy.js +33 -0
- data/node_modules/ws/LICENSE +21 -0
- data/node_modules/ws/README.md +259 -0
- data/node_modules/ws/SECURITY.md +33 -0
- data/node_modules/ws/index.js +15 -0
- data/node_modules/ws/lib/BufferUtil.fallback.js +56 -0
- data/node_modules/ws/lib/BufferUtil.js +15 -0
- data/node_modules/ws/lib/ErrorCodes.js +28 -0
- data/node_modules/ws/lib/EventTarget.js +158 -0
- data/node_modules/ws/lib/Extensions.js +69 -0
- data/node_modules/ws/lib/PerMessageDeflate.js +339 -0
- data/node_modules/ws/lib/Receiver.js +520 -0
- data/node_modules/ws/lib/Sender.js +438 -0
- data/node_modules/ws/lib/Validation.fallback.js +9 -0
- data/node_modules/ws/lib/Validation.js +17 -0
- data/node_modules/ws/lib/WebSocket.js +705 -0
- data/node_modules/ws/lib/WebSocketServer.js +336 -0
- data/node_modules/ws/package.json +122 -0
- data/package.json +26 -0
- data/samples/sample.html +13 -0
- data/script/rasterize.js +18 -0
- metadata +325 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ws: a node.js websocket client
|
|
3
|
+
* Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
|
|
4
|
+
* MIT Licensed
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const EventEmitter = require('events');
|
|
10
|
+
const crypto = require('crypto');
|
|
11
|
+
const Ultron = require('ultron');
|
|
12
|
+
const http = require('http');
|
|
13
|
+
const url = require('url');
|
|
14
|
+
|
|
15
|
+
const PerMessageDeflate = require('./PerMessageDeflate');
|
|
16
|
+
const Extensions = require('./Extensions');
|
|
17
|
+
const WebSocket = require('./WebSocket');
|
|
18
|
+
|
|
19
|
+
const GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Class representing a WebSocket server.
|
|
23
|
+
*
|
|
24
|
+
* @extends EventEmitter
|
|
25
|
+
*/
|
|
26
|
+
class WebSocketServer extends EventEmitter {
|
|
27
|
+
/**
|
|
28
|
+
* Create a `WebSocketServer` instance.
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} options Configuration options
|
|
31
|
+
* @param {String} options.host The hostname where to bind the server
|
|
32
|
+
* @param {Number} options.port The port where to bind the server
|
|
33
|
+
* @param {http.Server} options.server A pre-created HTTP/S server to use
|
|
34
|
+
* @param {Function} options.verifyClient An hook to reject connections
|
|
35
|
+
* @param {Function} options.handleProtocols An hook to handle protocols
|
|
36
|
+
* @param {String} options.path Accept only connections matching this path
|
|
37
|
+
* @param {Boolean} options.noServer Enable no server mode
|
|
38
|
+
* @param {Boolean} options.clientTracking Specifies whether or not to track clients
|
|
39
|
+
* @param {(Boolean|Object)} options.perMessageDeflate Enable/disable permessage-deflate
|
|
40
|
+
* @param {Number} options.maxPayload The maximum allowed message size
|
|
41
|
+
* @param {Function} callback A listener for the `listening` event
|
|
42
|
+
*/
|
|
43
|
+
constructor (options, callback) {
|
|
44
|
+
super();
|
|
45
|
+
|
|
46
|
+
options = Object.assign({
|
|
47
|
+
maxPayload: 100 * 1024 * 1024,
|
|
48
|
+
perMessageDeflate: true,
|
|
49
|
+
handleProtocols: null,
|
|
50
|
+
clientTracking: true,
|
|
51
|
+
verifyClient: null,
|
|
52
|
+
noServer: false,
|
|
53
|
+
backlog: null, // use default (511 as implemented in net.js)
|
|
54
|
+
server: null,
|
|
55
|
+
host: null,
|
|
56
|
+
path: null,
|
|
57
|
+
port: null
|
|
58
|
+
}, options);
|
|
59
|
+
|
|
60
|
+
if (options.port == null && !options.server && !options.noServer) {
|
|
61
|
+
throw new TypeError('missing or invalid options');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (options.port != null) {
|
|
65
|
+
this._server = http.createServer((req, res) => {
|
|
66
|
+
const body = http.STATUS_CODES[426];
|
|
67
|
+
|
|
68
|
+
res.writeHead(426, {
|
|
69
|
+
'Content-Length': body.length,
|
|
70
|
+
'Content-Type': 'text/plain'
|
|
71
|
+
});
|
|
72
|
+
res.end(body);
|
|
73
|
+
});
|
|
74
|
+
this._server.allowHalfOpen = false;
|
|
75
|
+
this._server.listen(options.port, options.host, options.backlog, callback);
|
|
76
|
+
} else if (options.server) {
|
|
77
|
+
this._server = options.server;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (this._server) {
|
|
81
|
+
this._ultron = new Ultron(this._server);
|
|
82
|
+
this._ultron.on('listening', () => this.emit('listening'));
|
|
83
|
+
this._ultron.on('error', (err) => this.emit('error', err));
|
|
84
|
+
this._ultron.on('upgrade', (req, socket, head) => {
|
|
85
|
+
this.handleUpgrade(req, socket, head, (client) => {
|
|
86
|
+
this.emit(`connection${req.url}`, client);
|
|
87
|
+
this.emit('connection', client);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (options.clientTracking) this.clients = new Set();
|
|
93
|
+
this.options = options;
|
|
94
|
+
this.path = options.path;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Close the server.
|
|
99
|
+
*
|
|
100
|
+
* @param {Function} cb Callback
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
close (cb) {
|
|
104
|
+
//
|
|
105
|
+
// Terminate all associated clients.
|
|
106
|
+
//
|
|
107
|
+
if (this.clients) {
|
|
108
|
+
for (const client of this.clients) client.terminate();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const server = this._server;
|
|
112
|
+
|
|
113
|
+
if (server) {
|
|
114
|
+
this._ultron.destroy();
|
|
115
|
+
this._ultron = this._server = null;
|
|
116
|
+
|
|
117
|
+
//
|
|
118
|
+
// Close the http server if it was internally created.
|
|
119
|
+
//
|
|
120
|
+
if (this.options.port != null) return server.close(cb);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (cb) cb();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* See if a given request should be handled by this server instance.
|
|
128
|
+
*
|
|
129
|
+
* @param {http.IncomingMessage} req Request object to inspect
|
|
130
|
+
* @return {Boolean} `true` if the request is valid, else `false`
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
shouldHandle (req) {
|
|
134
|
+
if (this.options.path && url.parse(req.url).pathname !== this.options.path) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Handle a HTTP Upgrade request.
|
|
143
|
+
*
|
|
144
|
+
* @param {http.IncomingMessage} req The request object
|
|
145
|
+
* @param {net.Socket} socket The network socket between the server and client
|
|
146
|
+
* @param {Buffer} head The first packet of the upgraded stream
|
|
147
|
+
* @param {Function} cb Callback
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
handleUpgrade (req, socket, head, cb) {
|
|
151
|
+
socket.on('error', socketError);
|
|
152
|
+
|
|
153
|
+
const version = +req.headers['sec-websocket-version'];
|
|
154
|
+
|
|
155
|
+
if (
|
|
156
|
+
!this.shouldHandle(req) ||
|
|
157
|
+
!req.headers.upgrade ||
|
|
158
|
+
req.headers.upgrade.toLowerCase() !== 'websocket' ||
|
|
159
|
+
!req.headers['sec-websocket-key'] ||
|
|
160
|
+
version !== 8 && version !== 13
|
|
161
|
+
) {
|
|
162
|
+
return abortConnection(socket, 400);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
var protocol = (req.headers['sec-websocket-protocol'] || '').split(/, */);
|
|
166
|
+
|
|
167
|
+
//
|
|
168
|
+
// Optionally call external protocol selection handler.
|
|
169
|
+
//
|
|
170
|
+
if (this.options.handleProtocols) {
|
|
171
|
+
protocol = this.options.handleProtocols(protocol);
|
|
172
|
+
if (protocol === false) return abortConnection(socket, 401);
|
|
173
|
+
} else {
|
|
174
|
+
protocol = protocol[0];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//
|
|
178
|
+
// Optionally call external client verification handler.
|
|
179
|
+
//
|
|
180
|
+
if (this.options.verifyClient) {
|
|
181
|
+
const info = {
|
|
182
|
+
origin: req.headers[`${version === 8 ? 'sec-websocket-origin' : 'origin'}`],
|
|
183
|
+
secure: !!(req.connection.authorized || req.connection.encrypted),
|
|
184
|
+
req
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
if (this.options.verifyClient.length === 2) {
|
|
188
|
+
this.options.verifyClient(info, (verified, code, message) => {
|
|
189
|
+
if (!verified) return abortConnection(socket, code || 401, message);
|
|
190
|
+
|
|
191
|
+
this.completeUpgrade(protocol, version, req, socket, head, cb);
|
|
192
|
+
});
|
|
193
|
+
return;
|
|
194
|
+
} else if (!this.options.verifyClient(info)) {
|
|
195
|
+
return abortConnection(socket, 401);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
this.completeUpgrade(protocol, version, req, socket, head, cb);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Upgrade the connection to WebSocket.
|
|
204
|
+
*
|
|
205
|
+
* @param {String} protocol The chosen subprotocol
|
|
206
|
+
* @param {Number} version The WebSocket protocol version
|
|
207
|
+
* @param {http.IncomingMessage} req The request object
|
|
208
|
+
* @param {net.Socket} socket The network socket between the server and client
|
|
209
|
+
* @param {Buffer} head The first packet of the upgraded stream
|
|
210
|
+
* @param {Function} cb Callback
|
|
211
|
+
* @private
|
|
212
|
+
*/
|
|
213
|
+
completeUpgrade (protocol, version, req, socket, head, cb) {
|
|
214
|
+
//
|
|
215
|
+
// Destroy the socket if the client has already sent a FIN packet.
|
|
216
|
+
//
|
|
217
|
+
if (!socket.readable || !socket.writable) return socket.destroy();
|
|
218
|
+
|
|
219
|
+
const key = crypto.createHash('sha1')
|
|
220
|
+
.update(req.headers['sec-websocket-key'] + GUID, 'binary')
|
|
221
|
+
.digest('base64');
|
|
222
|
+
|
|
223
|
+
const headers = [
|
|
224
|
+
'HTTP/1.1 101 Switching Protocols',
|
|
225
|
+
'Upgrade: websocket',
|
|
226
|
+
'Connection: Upgrade',
|
|
227
|
+
`Sec-WebSocket-Accept: ${key}`
|
|
228
|
+
];
|
|
229
|
+
|
|
230
|
+
if (protocol) headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
231
|
+
|
|
232
|
+
const offer = Extensions.parse(req.headers['sec-websocket-extensions']);
|
|
233
|
+
var extensions;
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
extensions = acceptExtensions(this.options, offer);
|
|
237
|
+
} catch (err) {
|
|
238
|
+
return abortConnection(socket, 400);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const props = Object.keys(extensions);
|
|
242
|
+
|
|
243
|
+
if (props.length) {
|
|
244
|
+
const serverExtensions = props.reduce((obj, key) => {
|
|
245
|
+
obj[key] = [extensions[key].params];
|
|
246
|
+
return obj;
|
|
247
|
+
}, {});
|
|
248
|
+
|
|
249
|
+
headers.push(`Sec-WebSocket-Extensions: ${Extensions.format(serverExtensions)}`);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
//
|
|
253
|
+
// Allow external modification/inspection of handshake headers.
|
|
254
|
+
//
|
|
255
|
+
this.emit('headers', headers);
|
|
256
|
+
|
|
257
|
+
socket.write(headers.concat('', '').join('\r\n'));
|
|
258
|
+
|
|
259
|
+
const client = new WebSocket([req, socket, head], {
|
|
260
|
+
maxPayload: this.options.maxPayload,
|
|
261
|
+
protocolVersion: version,
|
|
262
|
+
extensions,
|
|
263
|
+
protocol
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
if (this.clients) {
|
|
267
|
+
this.clients.add(client);
|
|
268
|
+
client.on('close', () => this.clients.delete(client));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
socket.removeListener('error', socketError);
|
|
272
|
+
cb(client);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
module.exports = WebSocketServer;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Handle premature socket errors.
|
|
280
|
+
*
|
|
281
|
+
* @private
|
|
282
|
+
*/
|
|
283
|
+
function socketError () {
|
|
284
|
+
this.destroy();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Accept WebSocket extensions.
|
|
289
|
+
*
|
|
290
|
+
* @param {Object} options The `WebSocketServer` configuration options
|
|
291
|
+
* @param {Object} offer The parsed value of the `sec-websocket-extensions` header
|
|
292
|
+
* @return {Object} Accepted extensions
|
|
293
|
+
* @private
|
|
294
|
+
*/
|
|
295
|
+
function acceptExtensions (options, offer) {
|
|
296
|
+
const pmd = options.perMessageDeflate;
|
|
297
|
+
const extensions = {};
|
|
298
|
+
|
|
299
|
+
if (pmd && offer[PerMessageDeflate.extensionName]) {
|
|
300
|
+
const perMessageDeflate = new PerMessageDeflate(
|
|
301
|
+
pmd !== true ? pmd : {},
|
|
302
|
+
true,
|
|
303
|
+
options.maxPayload
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
perMessageDeflate.accept(offer[PerMessageDeflate.extensionName]);
|
|
307
|
+
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return extensions;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Close the connection when preconditions are not fulfilled.
|
|
315
|
+
*
|
|
316
|
+
* @param {net.Socket} socket The socket of the upgrade request
|
|
317
|
+
* @param {Number} code The HTTP response status code
|
|
318
|
+
* @param {String} [message] The HTTP response body
|
|
319
|
+
* @private
|
|
320
|
+
*/
|
|
321
|
+
function abortConnection (socket, code, message) {
|
|
322
|
+
if (socket.writable) {
|
|
323
|
+
message = message || http.STATUS_CODES[code];
|
|
324
|
+
socket.write(
|
|
325
|
+
`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` +
|
|
326
|
+
'Connection: close\r\n' +
|
|
327
|
+
'Content-type: text/html\r\n' +
|
|
328
|
+
`Content-Length: ${Buffer.byteLength(message)}\r\n` +
|
|
329
|
+
'\r\n' +
|
|
330
|
+
message
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
socket.removeListener('error', socketError);
|
|
335
|
+
socket.destroy();
|
|
336
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_args": [
|
|
3
|
+
[
|
|
4
|
+
{
|
|
5
|
+
"raw": "ws@2.0.x",
|
|
6
|
+
"scope": null,
|
|
7
|
+
"escapedName": "ws",
|
|
8
|
+
"name": "ws",
|
|
9
|
+
"rawSpec": "2.0.x",
|
|
10
|
+
"spec": ">=2.0.0 <2.1.0",
|
|
11
|
+
"type": "range"
|
|
12
|
+
},
|
|
13
|
+
"/Users/tomascelizna/Devel/dragonfly_chrome_headless/node_modules/chrome-remote-interface"
|
|
14
|
+
]
|
|
15
|
+
],
|
|
16
|
+
"_from": "ws@>=2.0.0 <2.1.0",
|
|
17
|
+
"_id": "ws@2.0.3",
|
|
18
|
+
"_inCache": true,
|
|
19
|
+
"_location": "/ws",
|
|
20
|
+
"_nodeVersion": "7.5.0",
|
|
21
|
+
"_npmOperationalInternal": {
|
|
22
|
+
"host": "packages-18-east.internal.npmjs.com",
|
|
23
|
+
"tmp": "tmp/ws-2.0.3.tgz_1486561489812_0.7949141394346952"
|
|
24
|
+
},
|
|
25
|
+
"_npmUser": {
|
|
26
|
+
"name": "lpinca",
|
|
27
|
+
"email": "luigipinca@gmail.com"
|
|
28
|
+
},
|
|
29
|
+
"_npmVersion": "4.1.2",
|
|
30
|
+
"_phantomChildren": {},
|
|
31
|
+
"_requested": {
|
|
32
|
+
"raw": "ws@2.0.x",
|
|
33
|
+
"scope": null,
|
|
34
|
+
"escapedName": "ws",
|
|
35
|
+
"name": "ws",
|
|
36
|
+
"rawSpec": "2.0.x",
|
|
37
|
+
"spec": ">=2.0.0 <2.1.0",
|
|
38
|
+
"type": "range"
|
|
39
|
+
},
|
|
40
|
+
"_requiredBy": [
|
|
41
|
+
"/chrome-remote-interface"
|
|
42
|
+
],
|
|
43
|
+
"_resolved": "https://registry.npmjs.org/ws/-/ws-2.0.3.tgz",
|
|
44
|
+
"_shasum": "532fd499c3f7d7d720e543f1f807106cfc57d9cb",
|
|
45
|
+
"_shrinkwrap": null,
|
|
46
|
+
"_spec": "ws@2.0.x",
|
|
47
|
+
"_where": "/Users/tomascelizna/Devel/dragonfly_chrome_headless/node_modules/chrome-remote-interface",
|
|
48
|
+
"author": {
|
|
49
|
+
"name": "Einar Otto Stangvik",
|
|
50
|
+
"email": "einaros@gmail.com",
|
|
51
|
+
"url": "http://2x.io"
|
|
52
|
+
},
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/websockets/ws/issues"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"ultron": "~1.1.0"
|
|
58
|
+
},
|
|
59
|
+
"description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js",
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"benchmark": "~2.1.2",
|
|
62
|
+
"bufferutil": "~2.0.0",
|
|
63
|
+
"eslint": "~3.15.0",
|
|
64
|
+
"eslint-config-semistandard": "~7.0.0",
|
|
65
|
+
"eslint-config-standard": "~6.2.1",
|
|
66
|
+
"eslint-plugin-promise": "~3.4.0",
|
|
67
|
+
"eslint-plugin-standard": "~2.0.1",
|
|
68
|
+
"istanbul": "~0.4.5",
|
|
69
|
+
"mocha": "~3.2.0",
|
|
70
|
+
"utf-8-validate": "~3.0.0"
|
|
71
|
+
},
|
|
72
|
+
"directories": {},
|
|
73
|
+
"dist": {
|
|
74
|
+
"shasum": "532fd499c3f7d7d720e543f1f807106cfc57d9cb",
|
|
75
|
+
"tarball": "https://registry.npmjs.org/ws/-/ws-2.0.3.tgz"
|
|
76
|
+
},
|
|
77
|
+
"gitHead": "3918e11d200e574beca9d5abd61fbe3020434aed",
|
|
78
|
+
"homepage": "https://github.com/websockets/ws#readme",
|
|
79
|
+
"keywords": [
|
|
80
|
+
"HyBi",
|
|
81
|
+
"Push",
|
|
82
|
+
"RFC-6455",
|
|
83
|
+
"WebSocket",
|
|
84
|
+
"WebSockets",
|
|
85
|
+
"real-time"
|
|
86
|
+
],
|
|
87
|
+
"license": "MIT",
|
|
88
|
+
"main": "index.js",
|
|
89
|
+
"maintainers": [
|
|
90
|
+
{
|
|
91
|
+
"name": "3rdeden",
|
|
92
|
+
"email": "npm@3rd-Eden.com"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"name": "einaros",
|
|
96
|
+
"email": "einaros@gmail.com"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"name": "lpinca",
|
|
100
|
+
"email": "luigipinca@gmail.com"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "v1",
|
|
104
|
+
"email": "npm@3rd-Eden.com"
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
"name": "ws",
|
|
108
|
+
"optionalDependencies": {},
|
|
109
|
+
"readme": "ERROR: No README data found!",
|
|
110
|
+
"repository": {
|
|
111
|
+
"type": "git",
|
|
112
|
+
"url": "git://github.com/websockets/ws.git"
|
|
113
|
+
},
|
|
114
|
+
"scripts": {
|
|
115
|
+
"coverage": "istanbul cover _mocha --report html -- test/*.test.js",
|
|
116
|
+
"integration": "npm run lint && mocha test/*.integration.js",
|
|
117
|
+
"lint": "eslint .",
|
|
118
|
+
"test": "npm run lint && mocha test/*.test.js",
|
|
119
|
+
"test-travis": "npm run lint && istanbul cover _mocha --report lcovonly -- test/*.test.js"
|
|
120
|
+
},
|
|
121
|
+
"version": "2.0.3"
|
|
122
|
+
}
|