zmdms-utils 0.0.81 → 0.0.83

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.
Files changed (162) hide show
  1. package/dist/es/validate.js +168 -1
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -1
  4. package/package.json +2 -6
  5. package/src/index.ts +0 -3
  6. package/src/validate.ts +198 -0
  7. package/dist/es/_virtual/FastBufferList.js +0 -7
  8. package/dist/es/_virtual/_commonjs-dynamic-modules.js +0 -5
  9. package/dist/es/_virtual/browser.js +0 -7
  10. package/dist/es/_virtual/browser2.js +0 -7
  11. package/dist/es/_virtual/debug.js +0 -7
  12. package/dist/es/_virtual/event.js +0 -7
  13. package/dist/es/_virtual/http-parser.js +0 -3
  14. package/dist/es/_virtual/iframe.js +0 -7
  15. package/dist/es/_virtual/index.js +0 -7
  16. package/dist/es/_virtual/index2.js +0 -7
  17. package/dist/es/_virtual/index3.js +0 -7
  18. package/dist/es/_virtual/index4.js +0 -7
  19. package/dist/es/_virtual/index5.js +0 -7
  20. package/dist/es/_virtual/index6.js +0 -7
  21. package/dist/es/_virtual/index7.js +0 -3
  22. package/dist/es/_virtual/index8.js +0 -7
  23. package/dist/es/_virtual/index9.js +0 -7
  24. package/dist/es/_virtual/inherits.js +0 -7
  25. package/dist/es/_virtual/inherits_browser.js +0 -7
  26. package/dist/es/_virtual/json3.js +0 -7
  27. package/dist/es/_virtual/node.js +0 -7
  28. package/dist/es/_virtual/node2.js +0 -7
  29. package/dist/es/_virtual/stomp-node.js +0 -3
  30. package/dist/es/_virtual/stomp.js +0 -3
  31. package/dist/es/_virtual/streams.js +0 -3
  32. package/dist/es/_virtual/utils.js +0 -3
  33. package/dist/es/node_modules/bufferutil/fallback.js +0 -43
  34. package/dist/es/node_modules/bufferutil/index.js +0 -21
  35. package/dist/es/node_modules/debug/src/browser.js +0 -192
  36. package/dist/es/node_modules/debug/src/common.js +0 -259
  37. package/dist/es/node_modules/debug/src/index.js +0 -25
  38. package/dist/es/node_modules/debug/src/node.js +0 -192
  39. package/dist/es/node_modules/eventsource/lib/eventsource.js +0 -493
  40. package/dist/es/node_modules/faye-websocket/lib/faye/eventsource.js +0 -150
  41. package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api/event.js +0 -31
  42. package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api/event_target.js +0 -41
  43. package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api.js +0 -205
  44. package/dist/es/node_modules/faye-websocket/lib/faye/websocket/client.js +0 -107
  45. package/dist/es/node_modules/faye-websocket/lib/faye/websocket.js +0 -47
  46. package/dist/es/node_modules/has-flag/index.js +0 -17
  47. package/dist/es/node_modules/http-parser-js/http-parser.js +0 -471
  48. package/dist/es/node_modules/inherits/inherits.js +0 -14
  49. package/dist/es/node_modules/inherits/inherits_browser.js +0 -38
  50. package/dist/es/node_modules/is-typedarray/index.js +0 -51
  51. package/dist/es/node_modules/json3/lib/json3.js +0 -937
  52. package/dist/es/node_modules/ms/index.js +0 -172
  53. package/dist/es/node_modules/node-gyp-build/index.js +0 -21
  54. package/dist/es/node_modules/node-gyp-build/node-gyp-build.js +0 -222
  55. package/dist/es/node_modules/querystringify/index.js +0 -120
  56. package/dist/es/node_modules/requires-port/index.js +0 -38
  57. package/dist/es/node_modules/safe-buffer/index.js +0 -71
  58. package/dist/es/node_modules/supports-color/index.js +0 -143
  59. package/dist/es/node_modules/typedarray-to-buffer/index.js +0 -37
  60. package/dist/es/node_modules/url-parse/index.js +0 -594
  61. package/dist/es/node_modules/utf-8-validate/fallback.js +0 -71
  62. package/dist/es/node_modules/utf-8-validate/index.js +0 -21
  63. package/dist/es/node_modules/websocket/index.js +0 -15
  64. package/dist/es/node_modules/websocket/lib/Deprecation.js +0 -42
  65. package/dist/es/node_modules/websocket/lib/W3CWebSocket.js +0 -268
  66. package/dist/es/node_modules/websocket/lib/WebSocketClient.js +0 -380
  67. package/dist/es/node_modules/websocket/lib/WebSocketConnection.js +0 -914
  68. package/dist/es/node_modules/websocket/lib/WebSocketFrame.js +0 -293
  69. package/dist/es/node_modules/websocket/lib/WebSocketRequest.js +0 -543
  70. package/dist/es/node_modules/websocket/lib/WebSocketRouter.js +0 -172
  71. package/dist/es/node_modules/websocket/lib/WebSocketRouterRequest.js +0 -67
  72. package/dist/es/node_modules/websocket/lib/WebSocketServer.js +0 -272
  73. package/dist/es/node_modules/websocket/lib/utils.js +0 -80
  74. package/dist/es/node_modules/websocket/lib/version.js +0 -13
  75. package/dist/es/node_modules/websocket/lib/websocket.js +0 -31
  76. package/dist/es/node_modules/websocket/node_modules/debug/src/browser.js +0 -199
  77. package/dist/es/node_modules/websocket/node_modules/debug/src/debug.js +0 -215
  78. package/dist/es/node_modules/websocket/node_modules/debug/src/index.js +0 -25
  79. package/dist/es/node_modules/websocket/node_modules/debug/src/node.js +0 -266
  80. package/dist/es/node_modules/websocket/node_modules/ms/index.js +0 -162
  81. package/dist/es/node_modules/websocket/package.json.js +0 -77
  82. package/dist/es/node_modules/websocket/vendor/FastBufferList.js +0 -205
  83. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/base.js +0 -202
  84. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/client.js +0 -152
  85. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/draft75.js +0 -128
  86. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/draft76.js +0 -124
  87. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/headers.js +0 -44
  88. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi/frame.js +0 -21
  89. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi/message.js +0 -37
  90. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi.js +0 -492
  91. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/proxy.js +0 -108
  92. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/server.js +0 -119
  93. package/dist/es/node_modules/websocket-driver/lib/websocket/driver/stream_reader.js +0 -72
  94. package/dist/es/node_modules/websocket-driver/lib/websocket/driver.js +0 -47
  95. package/dist/es/node_modules/websocket-driver/lib/websocket/http_parser.js +0 -140
  96. package/dist/es/node_modules/websocket-driver/lib/websocket/streams.js +0 -150
  97. package/dist/es/node_modules/websocket-extensions/lib/parser.js +0 -103
  98. package/dist/es/node_modules/websocket-extensions/lib/pipeline/cell.js +0 -56
  99. package/dist/es/node_modules/websocket-extensions/lib/pipeline/functor.js +0 -74
  100. package/dist/es/node_modules/websocket-extensions/lib/pipeline/index.js +0 -50
  101. package/dist/es/node_modules/websocket-extensions/lib/pipeline/pledge.js +0 -39
  102. package/dist/es/node_modules/websocket-extensions/lib/pipeline/ring_buffer.js +0 -66
  103. package/dist/es/node_modules/websocket-extensions/lib/websocket_extensions.js +0 -165
  104. package/dist/es/node_modules/yaeti/index.js +0 -17
  105. package/dist/es/node_modules/yaeti/lib/Event.js +0 -24
  106. package/dist/es/node_modules/yaeti/lib/EventTarget.js +0 -130
  107. package/dist/es/node_modules/zt-sockjs-client/lib/entry.js +0 -14
  108. package/dist/es/node_modules/zt-sockjs-client/lib/event/close.js +0 -21
  109. package/dist/es/node_modules/zt-sockjs-client/lib/event/event.js +0 -22
  110. package/dist/es/node_modules/zt-sockjs-client/lib/event/eventtarget.js +0 -62
  111. package/dist/es/node_modules/zt-sockjs-client/lib/event/trans-message.js +0 -19
  112. package/dist/es/node_modules/zt-sockjs-client/lib/facade.js +0 -40
  113. package/dist/es/node_modules/zt-sockjs-client/lib/iframe-bootstrap.js +0 -122
  114. package/dist/es/node_modules/zt-sockjs-client/lib/info-ajax.js +0 -57
  115. package/dist/es/node_modules/zt-sockjs-client/lib/info-iframe-receiver.js +0 -50
  116. package/dist/es/node_modules/zt-sockjs-client/lib/info-iframe.js +0 -81
  117. package/dist/es/node_modules/zt-sockjs-client/lib/info-receiver.js +0 -101
  118. package/dist/es/node_modules/zt-sockjs-client/lib/location.js +0 -12
  119. package/dist/es/node_modules/zt-sockjs-client/lib/main.js +0 -413
  120. package/dist/es/node_modules/zt-sockjs-client/lib/shims.js +0 -449
  121. package/dist/es/node_modules/zt-sockjs-client/lib/transport/driver/websocket.js +0 -5
  122. package/dist/es/node_modules/zt-sockjs-client/lib/transport/driver/xhr.js +0 -80
  123. package/dist/es/node_modules/zt-sockjs-client/lib/transport/eventsource.js +0 -34
  124. package/dist/es/node_modules/zt-sockjs-client/lib/transport/htmlfile.js +0 -31
  125. package/dist/es/node_modules/zt-sockjs-client/lib/transport/iframe.js +0 -154
  126. package/dist/es/node_modules/zt-sockjs-client/lib/transport/jsonp-polling.js +0 -41
  127. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/ajax-based.js +0 -55
  128. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/buffered-sender.js +0 -92
  129. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/iframe-wrap.js +0 -39
  130. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/polling.js +0 -65
  131. package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/sender-receiver.js +0 -52
  132. package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/eventsource.js +0 -69
  133. package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/htmlfile.js +0 -96
  134. package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/jsonp.js +0 -193
  135. package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/xhr.js +0 -75
  136. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/jsonp.js +0 -104
  137. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xdr.js +0 -113
  138. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-cors.js +0 -19
  139. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-fake.js +0 -28
  140. package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-local.js +0 -21
  141. package/dist/es/node_modules/zt-sockjs-client/lib/transport/websocket.js +0 -108
  142. package/dist/es/node_modules/zt-sockjs-client/lib/transport/xdr-polling.js +0 -30
  143. package/dist/es/node_modules/zt-sockjs-client/lib/transport/xdr-streaming.js +0 -38
  144. package/dist/es/node_modules/zt-sockjs-client/lib/transport/xhr-polling.js +0 -40
  145. package/dist/es/node_modules/zt-sockjs-client/lib/transport/xhr-streaming.js +0 -50
  146. package/dist/es/node_modules/zt-sockjs-client/lib/transport-list.js +0 -28
  147. package/dist/es/node_modules/zt-sockjs-client/lib/utils/browser.js +0 -29
  148. package/dist/es/node_modules/zt-sockjs-client/lib/utils/escape.js +0 -53
  149. package/dist/es/node_modules/zt-sockjs-client/lib/utils/event.js +0 -78
  150. package/dist/es/node_modules/zt-sockjs-client/lib/utils/iframe.js +0 -205
  151. package/dist/es/node_modules/zt-sockjs-client/lib/utils/log.js +0 -20
  152. package/dist/es/node_modules/zt-sockjs-client/lib/utils/object.js +0 -24
  153. package/dist/es/node_modules/zt-sockjs-client/lib/utils/random.js +0 -30
  154. package/dist/es/node_modules/zt-sockjs-client/lib/utils/transport.js +0 -52
  155. package/dist/es/node_modules/zt-sockjs-client/lib/utils/url.js +0 -54
  156. package/dist/es/node_modules/zt-sockjs-client/lib/version.js +0 -11
  157. package/dist/es/node_modules/zt-stompjs/index.js +0 -23
  158. package/dist/es/node_modules/zt-stompjs/lib/stomp-node.js +0 -117
  159. package/dist/es/node_modules/zt-stompjs/lib/stomp.js +0 -536
  160. package/dist/es/stompClient.d.ts +0 -55
  161. package/dist/es/stompClient.js +0 -379
  162. package/src/stompClient.ts +0 -449
@@ -1,543 +0,0 @@
1
- import require$$0 from 'crypto';
2
- import require$$1$1 from 'util';
3
- import require$$2 from 'url';
4
- import require$$1 from 'events';
5
- import { __require as requireWebSocketConnection } from './WebSocketConnection.js';
6
-
7
- /************************************************************************
8
- * Copyright 2010-2015 Brian McKelvey.
9
- *
10
- * Licensed under the Apache License, Version 2.0 (the "License");
11
- * you may not use this file except in compliance with the License.
12
- * You may obtain a copy of the License at
13
- *
14
- * http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- ***********************************************************************/
22
-
23
- var WebSocketRequest_1;
24
- var hasRequiredWebSocketRequest;
25
-
26
- function requireWebSocketRequest () {
27
- if (hasRequiredWebSocketRequest) return WebSocketRequest_1;
28
- hasRequiredWebSocketRequest = 1;
29
- var crypto = require$$0;
30
- var util = require$$1$1;
31
- var url = require$$2;
32
- var EventEmitter = require$$1.EventEmitter;
33
- var WebSocketConnection = requireWebSocketConnection();
34
-
35
- var headerValueSplitRegExp = /,\s*/;
36
- var headerParamSplitRegExp = /;\s*/;
37
- var headerSanitizeRegExp = /[\r\n]/g;
38
- var xForwardedForSeparatorRegExp = /,\s*/;
39
- var separators = [
40
- '(', ')', '<', '>', '@',
41
- ',', ';', ':', '\\', '\"',
42
- '/', '[', ']', '?', '=',
43
- '{', '}', ' ', String.fromCharCode(9)
44
- ];
45
-
46
- var cookieNameValidateRegEx = /([\x00-\x20\x22\x28\x29\x2c\x2f\x3a-\x3f\x40\x5b-\x5e\x7b\x7d\x7f])/;
47
- var cookieValueValidateRegEx = /[^\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]/;
48
- var cookieValueDQuoteValidateRegEx = /^"[^"]*"$/;
49
- var controlCharsAndSemicolonRegEx = /[\x00-\x20\x3b]/g;
50
-
51
- var cookieSeparatorRegEx = /[;,] */;
52
-
53
- var httpStatusDescriptions = {
54
- 100: 'Continue',
55
- 101: 'Switching Protocols',
56
- 200: 'OK',
57
- 201: 'Created',
58
- 203: 'Non-Authoritative Information',
59
- 204: 'No Content',
60
- 205: 'Reset Content',
61
- 206: 'Partial Content',
62
- 300: 'Multiple Choices',
63
- 301: 'Moved Permanently',
64
- 302: 'Found',
65
- 303: 'See Other',
66
- 304: 'Not Modified',
67
- 305: 'Use Proxy',
68
- 307: 'Temporary Redirect',
69
- 400: 'Bad Request',
70
- 401: 'Unauthorized',
71
- 402: 'Payment Required',
72
- 403: 'Forbidden',
73
- 404: 'Not Found',
74
- 406: 'Not Acceptable',
75
- 407: 'Proxy Authorization Required',
76
- 408: 'Request Timeout',
77
- 409: 'Conflict',
78
- 410: 'Gone',
79
- 411: 'Length Required',
80
- 412: 'Precondition Failed',
81
- 413: 'Request Entity Too Long',
82
- 414: 'Request-URI Too Long',
83
- 415: 'Unsupported Media Type',
84
- 416: 'Requested Range Not Satisfiable',
85
- 417: 'Expectation Failed',
86
- 426: 'Upgrade Required',
87
- 500: 'Internal Server Error',
88
- 501: 'Not Implemented',
89
- 502: 'Bad Gateway',
90
- 503: 'Service Unavailable',
91
- 504: 'Gateway Timeout',
92
- 505: 'HTTP Version Not Supported'
93
- };
94
-
95
- function WebSocketRequest(socket, httpRequest, serverConfig) {
96
- // Superclass Constructor
97
- EventEmitter.call(this);
98
-
99
- this.socket = socket;
100
- this.httpRequest = httpRequest;
101
- this.resource = httpRequest.url;
102
- this.remoteAddress = socket.remoteAddress;
103
- this.remoteAddresses = [this.remoteAddress];
104
- this.serverConfig = serverConfig;
105
-
106
- // Watch for the underlying TCP socket closing before we call accept
107
- this._socketIsClosing = false;
108
- this._socketCloseHandler = this._handleSocketCloseBeforeAccept.bind(this);
109
- this.socket.on('end', this._socketCloseHandler);
110
- this.socket.on('close', this._socketCloseHandler);
111
-
112
- this._resolved = false;
113
- }
114
-
115
- util.inherits(WebSocketRequest, EventEmitter);
116
-
117
- WebSocketRequest.prototype.readHandshake = function() {
118
- var self = this;
119
- var request = this.httpRequest;
120
-
121
- // Decode URL
122
- this.resourceURL = url.parse(this.resource, true);
123
-
124
- this.host = request.headers['host'];
125
- if (!this.host) {
126
- throw new Error('Client must provide a Host header.');
127
- }
128
-
129
- this.key = request.headers['sec-websocket-key'];
130
- if (!this.key) {
131
- throw new Error('Client must provide a value for Sec-WebSocket-Key.');
132
- }
133
-
134
- this.webSocketVersion = parseInt(request.headers['sec-websocket-version'], 10);
135
-
136
- if (!this.webSocketVersion || isNaN(this.webSocketVersion)) {
137
- throw new Error('Client must provide a value for Sec-WebSocket-Version.');
138
- }
139
-
140
- switch (this.webSocketVersion) {
141
- case 8:
142
- case 13:
143
- break;
144
- default:
145
- var e = new Error('Unsupported websocket client version: ' + this.webSocketVersion +
146
- 'Only versions 8 and 13 are supported.');
147
- e.httpCode = 426;
148
- e.headers = {
149
- 'Sec-WebSocket-Version': '13'
150
- };
151
- throw e;
152
- }
153
-
154
- if (this.webSocketVersion === 13) {
155
- this.origin = request.headers['origin'];
156
- }
157
- else if (this.webSocketVersion === 8) {
158
- this.origin = request.headers['sec-websocket-origin'];
159
- }
160
-
161
- // Protocol is optional.
162
- var protocolString = request.headers['sec-websocket-protocol'];
163
- this.protocolFullCaseMap = {};
164
- this.requestedProtocols = [];
165
- if (protocolString) {
166
- var requestedProtocolsFullCase = protocolString.split(headerValueSplitRegExp);
167
- requestedProtocolsFullCase.forEach(function(protocol) {
168
- var lcProtocol = protocol.toLocaleLowerCase();
169
- self.requestedProtocols.push(lcProtocol);
170
- self.protocolFullCaseMap[lcProtocol] = protocol;
171
- });
172
- }
173
-
174
- if (!this.serverConfig.ignoreXForwardedFor &&
175
- request.headers['x-forwarded-for']) {
176
- var immediatePeerIP = this.remoteAddress;
177
- this.remoteAddresses = request.headers['x-forwarded-for']
178
- .split(xForwardedForSeparatorRegExp);
179
- this.remoteAddresses.push(immediatePeerIP);
180
- this.remoteAddress = this.remoteAddresses[0];
181
- }
182
-
183
- // Extensions are optional.
184
- if (this.serverConfig.parseExtensions) {
185
- var extensionsString = request.headers['sec-websocket-extensions'];
186
- this.requestedExtensions = this.parseExtensions(extensionsString);
187
- } else {
188
- this.requestedExtensions = [];
189
- }
190
-
191
- // Cookies are optional
192
- if (this.serverConfig.parseCookies) {
193
- var cookieString = request.headers['cookie'];
194
- this.cookies = this.parseCookies(cookieString);
195
- } else {
196
- this.cookies = [];
197
- }
198
- };
199
-
200
- WebSocketRequest.prototype.parseExtensions = function(extensionsString) {
201
- if (!extensionsString || extensionsString.length === 0) {
202
- return [];
203
- }
204
- var extensions = extensionsString.toLocaleLowerCase().split(headerValueSplitRegExp);
205
- extensions.forEach(function(extension, index, array) {
206
- var params = extension.split(headerParamSplitRegExp);
207
- var extensionName = params[0];
208
- var extensionParams = params.slice(1);
209
- extensionParams.forEach(function(rawParam, index, array) {
210
- var arr = rawParam.split('=');
211
- var obj = {
212
- name: arr[0],
213
- value: arr[1]
214
- };
215
- array.splice(index, 1, obj);
216
- });
217
- var obj = {
218
- name: extensionName,
219
- params: extensionParams
220
- };
221
- array.splice(index, 1, obj);
222
- });
223
- return extensions;
224
- };
225
-
226
- // This function adapted from node-cookie
227
- // https://github.com/shtylman/node-cookie
228
- WebSocketRequest.prototype.parseCookies = function(str) {
229
- // Sanity Check
230
- if (!str || typeof(str) !== 'string') {
231
- return [];
232
- }
233
-
234
- var cookies = [];
235
- var pairs = str.split(cookieSeparatorRegEx);
236
-
237
- pairs.forEach(function(pair) {
238
- var eq_idx = pair.indexOf('=');
239
- if (eq_idx === -1) {
240
- cookies.push({
241
- name: pair,
242
- value: null
243
- });
244
- return;
245
- }
246
-
247
- var key = pair.substr(0, eq_idx).trim();
248
- var val = pair.substr(++eq_idx, pair.length).trim();
249
-
250
- // quoted values
251
- if ('"' === val[0]) {
252
- val = val.slice(1, -1);
253
- }
254
-
255
- cookies.push({
256
- name: key,
257
- value: decodeURIComponent(val)
258
- });
259
- });
260
-
261
- return cookies;
262
- };
263
-
264
- WebSocketRequest.prototype.accept = function(acceptedProtocol, allowedOrigin, cookies) {
265
- this._verifyResolution();
266
-
267
- // TODO: Handle extensions
268
-
269
- var protocolFullCase;
270
-
271
- if (acceptedProtocol) {
272
- protocolFullCase = this.protocolFullCaseMap[acceptedProtocol.toLocaleLowerCase()];
273
- if (typeof(protocolFullCase) === 'undefined') {
274
- protocolFullCase = acceptedProtocol;
275
- }
276
- }
277
- else {
278
- protocolFullCase = acceptedProtocol;
279
- }
280
- this.protocolFullCaseMap = null;
281
-
282
- // Create key validation hash
283
- var sha1 = crypto.createHash('sha1');
284
- sha1.update(this.key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11');
285
- var acceptKey = sha1.digest('base64');
286
-
287
- var response = 'HTTP/1.1 101 Switching Protocols\r\n' +
288
- 'Upgrade: websocket\r\n' +
289
- 'Connection: Upgrade\r\n' +
290
- 'Sec-WebSocket-Accept: ' + acceptKey + '\r\n';
291
-
292
- if (protocolFullCase) {
293
- // validate protocol
294
- for (var i=0; i < protocolFullCase.length; i++) {
295
- var charCode = protocolFullCase.charCodeAt(i);
296
- var character = protocolFullCase.charAt(i);
297
- if (charCode < 0x21 || charCode > 0x7E || separators.indexOf(character) !== -1) {
298
- this.reject(500);
299
- throw new Error('Illegal character "' + String.fromCharCode(character) + '" in subprotocol.');
300
- }
301
- }
302
- if (this.requestedProtocols.indexOf(acceptedProtocol) === -1) {
303
- this.reject(500);
304
- throw new Error('Specified protocol was not requested by the client.');
305
- }
306
-
307
- protocolFullCase = protocolFullCase.replace(headerSanitizeRegExp, '');
308
- response += 'Sec-WebSocket-Protocol: ' + protocolFullCase + '\r\n';
309
- }
310
- this.requestedProtocols = null;
311
-
312
- if (allowedOrigin) {
313
- allowedOrigin = allowedOrigin.replace(headerSanitizeRegExp, '');
314
- if (this.webSocketVersion === 13) {
315
- response += 'Origin: ' + allowedOrigin + '\r\n';
316
- }
317
- else if (this.webSocketVersion === 8) {
318
- response += 'Sec-WebSocket-Origin: ' + allowedOrigin + '\r\n';
319
- }
320
- }
321
-
322
- if (cookies) {
323
- if (!Array.isArray(cookies)) {
324
- this.reject(500);
325
- throw new Error('Value supplied for "cookies" argument must be an array.');
326
- }
327
- var seenCookies = {};
328
- cookies.forEach(function(cookie) {
329
- if (!cookie.name || !cookie.value) {
330
- this.reject(500);
331
- throw new Error('Each cookie to set must at least provide a "name" and "value"');
332
- }
333
-
334
- // Make sure there are no \r\n sequences inserted
335
- cookie.name = cookie.name.replace(controlCharsAndSemicolonRegEx, '');
336
- cookie.value = cookie.value.replace(controlCharsAndSemicolonRegEx, '');
337
-
338
- if (seenCookies[cookie.name]) {
339
- this.reject(500);
340
- throw new Error('You may not specify the same cookie name twice.');
341
- }
342
- seenCookies[cookie.name] = true;
343
-
344
- // token (RFC 2616, Section 2.2)
345
- var invalidChar = cookie.name.match(cookieNameValidateRegEx);
346
- if (invalidChar) {
347
- this.reject(500);
348
- throw new Error('Illegal character ' + invalidChar[0] + ' in cookie name');
349
- }
350
-
351
- // RFC 6265, Section 4.1.1
352
- // *cookie-octet / ( DQUOTE *cookie-octet DQUOTE ) | %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
353
- if (cookie.value.match(cookieValueDQuoteValidateRegEx)) {
354
- invalidChar = cookie.value.slice(1, -1).match(cookieValueValidateRegEx);
355
- } else {
356
- invalidChar = cookie.value.match(cookieValueValidateRegEx);
357
- }
358
- if (invalidChar) {
359
- this.reject(500);
360
- throw new Error('Illegal character ' + invalidChar[0] + ' in cookie value');
361
- }
362
-
363
- var cookieParts = [cookie.name + '=' + cookie.value];
364
-
365
- // RFC 6265, Section 4.1.1
366
- // 'Path=' path-value | <any CHAR except CTLs or ';'>
367
- if(cookie.path){
368
- invalidChar = cookie.path.match(controlCharsAndSemicolonRegEx);
369
- if (invalidChar) {
370
- this.reject(500);
371
- throw new Error('Illegal character ' + invalidChar[0] + ' in cookie path');
372
- }
373
- cookieParts.push('Path=' + cookie.path);
374
- }
375
-
376
- // RFC 6265, Section 4.1.2.3
377
- // 'Domain=' subdomain
378
- if (cookie.domain) {
379
- if (typeof(cookie.domain) !== 'string') {
380
- this.reject(500);
381
- throw new Error('Domain must be specified and must be a string.');
382
- }
383
- invalidChar = cookie.domain.match(controlCharsAndSemicolonRegEx);
384
- if (invalidChar) {
385
- this.reject(500);
386
- throw new Error('Illegal character ' + invalidChar[0] + ' in cookie domain');
387
- }
388
- cookieParts.push('Domain=' + cookie.domain.toLowerCase());
389
- }
390
-
391
- // RFC 6265, Section 4.1.1
392
- //'Expires=' sane-cookie-date | Force Date object requirement by using only epoch
393
- if (cookie.expires) {
394
- if (!(cookie.expires instanceof Date)){
395
- this.reject(500);
396
- throw new Error('Value supplied for cookie "expires" must be a vaild date object');
397
- }
398
- cookieParts.push('Expires=' + cookie.expires.toGMTString());
399
- }
400
-
401
- // RFC 6265, Section 4.1.1
402
- //'Max-Age=' non-zero-digit *DIGIT
403
- if (cookie.maxage) {
404
- var maxage = cookie.maxage;
405
- if (typeof(maxage) === 'string') {
406
- maxage = parseInt(maxage, 10);
407
- }
408
- if (isNaN(maxage) || maxage <= 0 ) {
409
- this.reject(500);
410
- throw new Error('Value supplied for cookie "maxage" must be a non-zero number');
411
- }
412
- maxage = Math.round(maxage);
413
- cookieParts.push('Max-Age=' + maxage.toString(10));
414
- }
415
-
416
- // RFC 6265, Section 4.1.1
417
- //'Secure;'
418
- if (cookie.secure) {
419
- if (typeof(cookie.secure) !== 'boolean') {
420
- this.reject(500);
421
- throw new Error('Value supplied for cookie "secure" must be of type boolean');
422
- }
423
- cookieParts.push('Secure');
424
- }
425
-
426
- // RFC 6265, Section 4.1.1
427
- //'HttpOnly;'
428
- if (cookie.httponly) {
429
- if (typeof(cookie.httponly) !== 'boolean') {
430
- this.reject(500);
431
- throw new Error('Value supplied for cookie "httponly" must be of type boolean');
432
- }
433
- cookieParts.push('HttpOnly');
434
- }
435
-
436
- response += ('Set-Cookie: ' + cookieParts.join(';') + '\r\n');
437
- }.bind(this));
438
- }
439
-
440
- // TODO: handle negotiated extensions
441
- // if (negotiatedExtensions) {
442
- // response += 'Sec-WebSocket-Extensions: ' + negotiatedExtensions.join(', ') + '\r\n';
443
- // }
444
-
445
- // Mark the request resolved now so that the user can't call accept or
446
- // reject a second time.
447
- this._resolved = true;
448
- this.emit('requestResolved', this);
449
-
450
- response += '\r\n';
451
-
452
- var connection = new WebSocketConnection(this.socket, [], acceptedProtocol, false, this.serverConfig);
453
- connection.webSocketVersion = this.webSocketVersion;
454
- connection.remoteAddress = this.remoteAddress;
455
- connection.remoteAddresses = this.remoteAddresses;
456
-
457
- var self = this;
458
-
459
- if (this._socketIsClosing) {
460
- // Handle case when the client hangs up before we get a chance to
461
- // accept the connection and send our side of the opening handshake.
462
- cleanupFailedConnection(connection);
463
- }
464
- else {
465
- this.socket.write(response, 'ascii', function(error) {
466
- if (error) {
467
- cleanupFailedConnection(connection);
468
- return;
469
- }
470
-
471
- self._removeSocketCloseListeners();
472
- connection._addSocketEventListeners();
473
- });
474
- }
475
-
476
- this.emit('requestAccepted', connection);
477
- return connection;
478
- };
479
-
480
- WebSocketRequest.prototype.reject = function(status, reason, extraHeaders) {
481
- this._verifyResolution();
482
-
483
- // Mark the request resolved now so that the user can't call accept or
484
- // reject a second time.
485
- this._resolved = true;
486
- this.emit('requestResolved', this);
487
-
488
- if (typeof(status) !== 'number') {
489
- status = 403;
490
- }
491
- var response = 'HTTP/1.1 ' + status + ' ' + httpStatusDescriptions[status] + '\r\n' +
492
- 'Connection: close\r\n';
493
- if (reason) {
494
- reason = reason.replace(headerSanitizeRegExp, '');
495
- response += 'X-WebSocket-Reject-Reason: ' + reason + '\r\n';
496
- }
497
-
498
- if (extraHeaders) {
499
- for (var key in extraHeaders) {
500
- var sanitizedValue = extraHeaders[key].toString().replace(headerSanitizeRegExp, '');
501
- var sanitizedKey = key.replace(headerSanitizeRegExp, '');
502
- response += (sanitizedKey + ': ' + sanitizedValue + '\r\n');
503
- }
504
- }
505
-
506
- response += '\r\n';
507
- this.socket.end(response, 'ascii');
508
-
509
- this.emit('requestRejected', this);
510
- };
511
-
512
- WebSocketRequest.prototype._handleSocketCloseBeforeAccept = function() {
513
- this._socketIsClosing = true;
514
- this._removeSocketCloseListeners();
515
- };
516
-
517
- WebSocketRequest.prototype._removeSocketCloseListeners = function() {
518
- this.socket.removeListener('end', this._socketCloseHandler);
519
- this.socket.removeListener('close', this._socketCloseHandler);
520
- };
521
-
522
- WebSocketRequest.prototype._verifyResolution = function() {
523
- if (this._resolved) {
524
- throw new Error('WebSocketRequest may only be accepted or rejected one time.');
525
- }
526
- };
527
-
528
- function cleanupFailedConnection(connection) {
529
- // Since we have to return a connection object even if the socket is
530
- // already dead in order not to break the API, we schedule a 'close'
531
- // event on the connection object to occur immediately.
532
- process.nextTick(function() {
533
- // WebSocketConnection.CLOSE_REASON_ABNORMAL = 1006
534
- // Third param: Skip sending the close frame to a dead socket
535
- connection.drop(1006, 'TCP connection lost before handshake completed.', true);
536
- });
537
- }
538
-
539
- WebSocketRequest_1 = WebSocketRequest;
540
- return WebSocketRequest_1;
541
- }
542
-
543
- export { requireWebSocketRequest as __require };