@databricks/sql 1.2.0 → 1.2.1
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.
- package/README.md +2 -2
- package/dist/DBSQLClient.d.ts +2 -3
- package/dist/DBSQLClient.js +17 -18
- package/dist/DBSQLClient.js.map +1 -1
- package/dist/DBSQLOperation/CompleteOperationHelper.d.ts +3 -3
- package/dist/DBSQLOperation/CompleteOperationHelper.js +12 -17
- package/dist/DBSQLOperation/CompleteOperationHelper.js.map +1 -1
- package/dist/DBSQLOperation/FetchResultsHelper.d.ts +4 -5
- package/dist/DBSQLOperation/FetchResultsHelper.js +16 -12
- package/dist/DBSQLOperation/FetchResultsHelper.js.map +1 -1
- package/dist/DBSQLOperation/OperationStatusHelper.d.ts +2 -3
- package/dist/DBSQLOperation/OperationStatusHelper.js +12 -12
- package/dist/DBSQLOperation/OperationStatusHelper.js.map +1 -1
- package/dist/DBSQLOperation/SchemaHelper.d.ts +2 -3
- package/dist/DBSQLOperation/SchemaHelper.js +2 -3
- package/dist/DBSQLOperation/SchemaHelper.js.map +1 -1
- package/dist/DBSQLOperation/index.d.ts +7 -7
- package/dist/DBSQLOperation/index.js +18 -11
- package/dist/DBSQLOperation/index.js.map +1 -1
- package/dist/DBSQLSession.d.ts +3 -5
- package/dist/DBSQLSession.js +63 -49
- package/dist/DBSQLSession.js.map +1 -1
- package/dist/connection/auth/NoSaslAuthentication.js +0 -1
- package/dist/connection/auth/NoSaslAuthentication.js.map +1 -1
- package/dist/connection/auth/PlainHttpAuthentication.js +1 -1
- package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -1
- package/dist/connection/contracts/ITransport.d.ts +0 -7
- package/dist/connection/transports/HttpTransport.d.ts +0 -6
- package/dist/connection/transports/HttpTransport.js +0 -6
- package/dist/connection/transports/HttpTransport.js.map +1 -1
- package/dist/dto/Status.d.ts +9 -13
- package/dist/dto/Status.js +31 -10
- package/dist/dto/Status.js.map +1 -1
- package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/http_connection.js +2 -0
- package/dist/result/JsonResult.js +3 -0
- package/dist/result/JsonResult.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -5
- package/dist/factory/StatusFactory.d.ts +0 -12
- package/dist/factory/StatusFactory.js +0 -35
- package/dist/factory/StatusFactory.js.map +0 -1
- package/node_modules/async-limiter/.eslintignore +0 -2
- package/node_modules/async-limiter/.nycrc +0 -10
- package/node_modules/async-limiter/.travis.yml +0 -9
- package/node_modules/async-limiter/LICENSE +0 -8
- package/node_modules/async-limiter/index.js +0 -67
- package/node_modules/async-limiter/package.json +0 -35
- package/node_modules/async-limiter/readme.md +0 -132
- package/node_modules/browser-or-node/LICENSE +0 -21
- package/node_modules/browser-or-node/README.md +0 -63
- package/node_modules/browser-or-node/lib/index.js +0 -31
- package/node_modules/browser-or-node/package.json +0 -60
- package/node_modules/browser-or-node/src/index.js +0 -26
- package/node_modules/isomorphic-ws/LICENSE +0 -21
- package/node_modules/isomorphic-ws/README.md +0 -58
- package/node_modules/isomorphic-ws/browser.js +0 -17
- package/node_modules/isomorphic-ws/index.d.ts +0 -8
- package/node_modules/isomorphic-ws/node.js +0 -3
- package/node_modules/isomorphic-ws/package.json +0 -34
- package/node_modules/node-int64/.npmignore +0 -3
- package/node_modules/node-int64/Int64.js +0 -268
- package/node_modules/node-int64/LICENSE +0 -19
- package/node_modules/node-int64/README.md +0 -78
- package/node_modules/node-int64/package.json +0 -27
- package/node_modules/node-int64/test.js +0 -120
- package/node_modules/q/CHANGES.md +0 -800
- package/node_modules/q/LICENSE +0 -18
- package/node_modules/q/README.md +0 -874
- package/node_modules/q/package.json +0 -76
- package/node_modules/q/q.js +0 -2076
- package/node_modules/q/queue.js +0 -35
- package/node_modules/ws/LICENSE +0 -21
- package/node_modules/ws/README.md +0 -417
- package/node_modules/ws/index.js +0 -9
- package/node_modules/ws/lib/buffer-util.js +0 -72
- package/node_modules/ws/lib/constants.js +0 -10
- package/node_modules/ws/lib/event-target.js +0 -170
- package/node_modules/ws/lib/extension.js +0 -211
- package/node_modules/ws/lib/permessage-deflate.js +0 -516
- package/node_modules/ws/lib/receiver.js +0 -513
- package/node_modules/ws/lib/sender.js +0 -401
- package/node_modules/ws/lib/validation.js +0 -29
- package/node_modules/ws/lib/websocket-server.js +0 -369
- package/node_modules/ws/lib/websocket.js +0 -828
- package/node_modules/ws/package.json +0 -44
- /package/{node_modules → dist/node_modules}/thrift/LICENSE +0 -0
- /package/{node_modules → dist/node_modules}/thrift/README.md +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/README.md +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/binary.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/binary_protocol.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/browser.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/buffered_transport.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/compact_protocol.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/connection.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/create_client.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/framed_transport.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/header_protocol.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/header_transport.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/index.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/input_buffer_underrun_error.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/int64_util.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/json_parse.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/json_protocol.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/log.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/multiplexed_processor.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/multiplexed_protocol.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/protocol.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/server.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/thrift.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/transport.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/web_server.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/ws_connection.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/ws_transport.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/lib/nodejs/lib/thrift/xhr_connection.js +0 -0
- /package/{node_modules → dist/node_modules}/thrift/package.json +0 -0
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const EventEmitter = require('events');
|
|
4
|
-
const crypto = require('crypto');
|
|
5
|
-
const http = require('http');
|
|
6
|
-
const url = require('url');
|
|
7
|
-
|
|
8
|
-
const PerMessageDeflate = require('./permessage-deflate');
|
|
9
|
-
const extension = require('./extension');
|
|
10
|
-
const constants = require('./constants');
|
|
11
|
-
const WebSocket = require('./websocket');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Class representing a WebSocket server.
|
|
15
|
-
*
|
|
16
|
-
* @extends EventEmitter
|
|
17
|
-
*/
|
|
18
|
-
class WebSocketServer extends EventEmitter {
|
|
19
|
-
/**
|
|
20
|
-
* Create a `WebSocketServer` instance.
|
|
21
|
-
*
|
|
22
|
-
* @param {Object} options Configuration options
|
|
23
|
-
* @param {String} options.host The hostname where to bind the server
|
|
24
|
-
* @param {Number} options.port The port where to bind the server
|
|
25
|
-
* @param {http.Server} options.server A pre-created HTTP/S server to use
|
|
26
|
-
* @param {Function} options.verifyClient An hook to reject connections
|
|
27
|
-
* @param {Function} options.handleProtocols An hook to handle protocols
|
|
28
|
-
* @param {String} options.path Accept only connections matching this path
|
|
29
|
-
* @param {Boolean} options.noServer Enable no server mode
|
|
30
|
-
* @param {Boolean} options.clientTracking Specifies whether or not to track clients
|
|
31
|
-
* @param {(Boolean|Object)} options.perMessageDeflate Enable/disable permessage-deflate
|
|
32
|
-
* @param {Number} options.maxPayload The maximum allowed message size
|
|
33
|
-
* @param {Function} callback A listener for the `listening` event
|
|
34
|
-
*/
|
|
35
|
-
constructor (options, callback) {
|
|
36
|
-
super();
|
|
37
|
-
|
|
38
|
-
options = Object.assign({
|
|
39
|
-
maxPayload: 100 * 1024 * 1024,
|
|
40
|
-
perMessageDeflate: false,
|
|
41
|
-
handleProtocols: null,
|
|
42
|
-
clientTracking: true,
|
|
43
|
-
verifyClient: null,
|
|
44
|
-
noServer: false,
|
|
45
|
-
backlog: null, // use default (511 as implemented in net.js)
|
|
46
|
-
server: null,
|
|
47
|
-
host: null,
|
|
48
|
-
path: null,
|
|
49
|
-
port: null
|
|
50
|
-
}, options);
|
|
51
|
-
|
|
52
|
-
if (options.port == null && !options.server && !options.noServer) {
|
|
53
|
-
throw new TypeError(
|
|
54
|
-
'One of the "port", "server", or "noServer" options must be specified'
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (options.port != null) {
|
|
59
|
-
this._server = http.createServer((req, res) => {
|
|
60
|
-
const body = http.STATUS_CODES[426];
|
|
61
|
-
|
|
62
|
-
res.writeHead(426, {
|
|
63
|
-
'Content-Length': body.length,
|
|
64
|
-
'Content-Type': 'text/plain'
|
|
65
|
-
});
|
|
66
|
-
res.end(body);
|
|
67
|
-
});
|
|
68
|
-
this._server.listen(options.port, options.host, options.backlog, callback);
|
|
69
|
-
} else if (options.server) {
|
|
70
|
-
this._server = options.server;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (this._server) {
|
|
74
|
-
this._removeListeners = addListeners(this._server, {
|
|
75
|
-
listening: this.emit.bind(this, 'listening'),
|
|
76
|
-
error: this.emit.bind(this, 'error'),
|
|
77
|
-
upgrade: (req, socket, head) => {
|
|
78
|
-
this.handleUpgrade(req, socket, head, (ws) => {
|
|
79
|
-
this.emit('connection', ws, req);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (options.perMessageDeflate === true) options.perMessageDeflate = {};
|
|
86
|
-
if (options.clientTracking) this.clients = new Set();
|
|
87
|
-
this.options = options;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Returns the bound address, the address family name, and port of the server
|
|
92
|
-
* as reported by the operating system if listening on an IP socket.
|
|
93
|
-
* If the server is listening on a pipe or UNIX domain socket, the name is
|
|
94
|
-
* returned as a string.
|
|
95
|
-
*
|
|
96
|
-
* @return {(Object|String|null)} The address of the server
|
|
97
|
-
* @public
|
|
98
|
-
*/
|
|
99
|
-
address () {
|
|
100
|
-
if (this.options.noServer) {
|
|
101
|
-
throw new Error('The server is operating in "noServer" mode');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (!this._server) return null;
|
|
105
|
-
return this._server.address();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Close the server.
|
|
110
|
-
*
|
|
111
|
-
* @param {Function} cb Callback
|
|
112
|
-
* @public
|
|
113
|
-
*/
|
|
114
|
-
close (cb) {
|
|
115
|
-
//
|
|
116
|
-
// Terminate all associated clients.
|
|
117
|
-
//
|
|
118
|
-
if (this.clients) {
|
|
119
|
-
for (const client of this.clients) client.terminate();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const server = this._server;
|
|
123
|
-
|
|
124
|
-
if (server) {
|
|
125
|
-
this._removeListeners();
|
|
126
|
-
this._removeListeners = this._server = null;
|
|
127
|
-
|
|
128
|
-
//
|
|
129
|
-
// Close the http server if it was internally created.
|
|
130
|
-
//
|
|
131
|
-
if (this.options.port != null) return server.close(cb);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (cb) cb();
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* See if a given request should be handled by this server instance.
|
|
139
|
-
*
|
|
140
|
-
* @param {http.IncomingMessage} req Request object to inspect
|
|
141
|
-
* @return {Boolean} `true` if the request is valid, else `false`
|
|
142
|
-
* @public
|
|
143
|
-
*/
|
|
144
|
-
shouldHandle (req) {
|
|
145
|
-
if (this.options.path && url.parse(req.url).pathname !== this.options.path) {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Handle a HTTP Upgrade request.
|
|
154
|
-
*
|
|
155
|
-
* @param {http.IncomingMessage} req The request object
|
|
156
|
-
* @param {net.Socket} socket The network socket between the server and client
|
|
157
|
-
* @param {Buffer} head The first packet of the upgraded stream
|
|
158
|
-
* @param {Function} cb Callback
|
|
159
|
-
* @public
|
|
160
|
-
*/
|
|
161
|
-
handleUpgrade (req, socket, head, cb) {
|
|
162
|
-
socket.on('error', socketOnError);
|
|
163
|
-
|
|
164
|
-
const version = +req.headers['sec-websocket-version'];
|
|
165
|
-
const extensions = {};
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
req.method !== 'GET' || req.headers.upgrade.toLowerCase() !== 'websocket' ||
|
|
169
|
-
!req.headers['sec-websocket-key'] || (version !== 8 && version !== 13) ||
|
|
170
|
-
!this.shouldHandle(req)
|
|
171
|
-
) {
|
|
172
|
-
return abortHandshake(socket, 400);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (this.options.perMessageDeflate) {
|
|
176
|
-
const perMessageDeflate = new PerMessageDeflate(
|
|
177
|
-
this.options.perMessageDeflate,
|
|
178
|
-
true,
|
|
179
|
-
this.options.maxPayload
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
const offers = extension.parse(
|
|
184
|
-
req.headers['sec-websocket-extensions']
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
if (offers[PerMessageDeflate.extensionName]) {
|
|
188
|
-
perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
|
|
189
|
-
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
190
|
-
}
|
|
191
|
-
} catch (err) {
|
|
192
|
-
return abortHandshake(socket, 400);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
//
|
|
197
|
-
// Optionally call external client verification handler.
|
|
198
|
-
//
|
|
199
|
-
if (this.options.verifyClient) {
|
|
200
|
-
const info = {
|
|
201
|
-
origin: req.headers[`${version === 8 ? 'sec-websocket-origin' : 'origin'}`],
|
|
202
|
-
secure: !!(req.connection.authorized || req.connection.encrypted),
|
|
203
|
-
req
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
if (this.options.verifyClient.length === 2) {
|
|
207
|
-
this.options.verifyClient(info, (verified, code, message, headers) => {
|
|
208
|
-
if (!verified) {
|
|
209
|
-
return abortHandshake(socket, code || 401, message, headers);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
this.completeUpgrade(extensions, req, socket, head, cb);
|
|
213
|
-
});
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
this.completeUpgrade(extensions, req, socket, head, cb);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Upgrade the connection to WebSocket.
|
|
225
|
-
*
|
|
226
|
-
* @param {Object} extensions The accepted extensions
|
|
227
|
-
* @param {http.IncomingMessage} req The request object
|
|
228
|
-
* @param {net.Socket} socket The network socket between the server and client
|
|
229
|
-
* @param {Buffer} head The first packet of the upgraded stream
|
|
230
|
-
* @param {Function} cb Callback
|
|
231
|
-
* @private
|
|
232
|
-
*/
|
|
233
|
-
completeUpgrade (extensions, req, socket, head, cb) {
|
|
234
|
-
//
|
|
235
|
-
// Destroy the socket if the client has already sent a FIN packet.
|
|
236
|
-
//
|
|
237
|
-
if (!socket.readable || !socket.writable) return socket.destroy();
|
|
238
|
-
|
|
239
|
-
const key = crypto.createHash('sha1')
|
|
240
|
-
.update(req.headers['sec-websocket-key'] + constants.GUID, 'binary')
|
|
241
|
-
.digest('base64');
|
|
242
|
-
|
|
243
|
-
const headers = [
|
|
244
|
-
'HTTP/1.1 101 Switching Protocols',
|
|
245
|
-
'Upgrade: websocket',
|
|
246
|
-
'Connection: Upgrade',
|
|
247
|
-
`Sec-WebSocket-Accept: ${key}`
|
|
248
|
-
];
|
|
249
|
-
|
|
250
|
-
const ws = new WebSocket(null);
|
|
251
|
-
var protocol = req.headers['sec-websocket-protocol'];
|
|
252
|
-
|
|
253
|
-
if (protocol) {
|
|
254
|
-
protocol = protocol.split(',').map(trim);
|
|
255
|
-
|
|
256
|
-
//
|
|
257
|
-
// Optionally call external protocol selection handler.
|
|
258
|
-
//
|
|
259
|
-
if (this.options.handleProtocols) {
|
|
260
|
-
protocol = this.options.handleProtocols(protocol, req);
|
|
261
|
-
} else {
|
|
262
|
-
protocol = protocol[0];
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (protocol) {
|
|
266
|
-
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
267
|
-
ws.protocol = protocol;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if (extensions[PerMessageDeflate.extensionName]) {
|
|
272
|
-
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
273
|
-
const value = extension.format({
|
|
274
|
-
[PerMessageDeflate.extensionName]: [params]
|
|
275
|
-
});
|
|
276
|
-
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
|
277
|
-
ws._extensions = extensions;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
//
|
|
281
|
-
// Allow external modification/inspection of handshake headers.
|
|
282
|
-
//
|
|
283
|
-
this.emit('headers', headers, req);
|
|
284
|
-
|
|
285
|
-
socket.write(headers.concat('\r\n').join('\r\n'));
|
|
286
|
-
socket.removeListener('error', socketOnError);
|
|
287
|
-
|
|
288
|
-
ws.setSocket(socket, head, this.options.maxPayload);
|
|
289
|
-
|
|
290
|
-
if (this.clients) {
|
|
291
|
-
this.clients.add(ws);
|
|
292
|
-
ws.on('close', () => this.clients.delete(ws));
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
cb(ws);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
module.exports = WebSocketServer;
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Add event listeners on an `EventEmitter` using a map of <event, listener>
|
|
303
|
-
* pairs.
|
|
304
|
-
*
|
|
305
|
-
* @param {EventEmitter} server The event emitter
|
|
306
|
-
* @param {Object.<String, Function>} map The listeners to add
|
|
307
|
-
* @return {Function} A function that will remove the added listeners when called
|
|
308
|
-
* @private
|
|
309
|
-
*/
|
|
310
|
-
function addListeners (server, map) {
|
|
311
|
-
for (const event of Object.keys(map)) server.on(event, map[event]);
|
|
312
|
-
|
|
313
|
-
return function removeListeners () {
|
|
314
|
-
for (const event of Object.keys(map)) {
|
|
315
|
-
server.removeListener(event, map[event]);
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Handle premature socket errors.
|
|
322
|
-
*
|
|
323
|
-
* @private
|
|
324
|
-
*/
|
|
325
|
-
function socketOnError () {
|
|
326
|
-
this.destroy();
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Close the connection when preconditions are not fulfilled.
|
|
331
|
-
*
|
|
332
|
-
* @param {net.Socket} socket The socket of the upgrade request
|
|
333
|
-
* @param {Number} code The HTTP response status code
|
|
334
|
-
* @param {String} [message] The HTTP response body
|
|
335
|
-
* @param {Object} [headers] Additional HTTP response headers
|
|
336
|
-
* @private
|
|
337
|
-
*/
|
|
338
|
-
function abortHandshake (socket, code, message, headers) {
|
|
339
|
-
if (socket.writable) {
|
|
340
|
-
message = message || http.STATUS_CODES[code];
|
|
341
|
-
headers = Object.assign({
|
|
342
|
-
'Connection': 'close',
|
|
343
|
-
'Content-type': 'text/html',
|
|
344
|
-
'Content-Length': Buffer.byteLength(message)
|
|
345
|
-
}, headers);
|
|
346
|
-
|
|
347
|
-
socket.write(
|
|
348
|
-
`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` +
|
|
349
|
-
Object.keys(headers).map(h => `${h}: ${headers[h]}`).join('\r\n') +
|
|
350
|
-
'\r\n\r\n' +
|
|
351
|
-
message
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
socket.removeListener('error', socketOnError);
|
|
356
|
-
socket.destroy();
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Remove whitespace characters from both ends of a string.
|
|
361
|
-
*
|
|
362
|
-
* @param {String} str The string
|
|
363
|
-
* @return {String} A new string representing `str` stripped of whitespace
|
|
364
|
-
* characters from both its beginning and end
|
|
365
|
-
* @private
|
|
366
|
-
*/
|
|
367
|
-
function trim(str) {
|
|
368
|
-
return str.trim();
|
|
369
|
-
}
|