zmdms-utils 0.0.80 → 0.0.81
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/declarations.d.ts +6 -0
- package/dist/es/_virtual/FastBufferList.js +7 -0
- package/dist/es/_virtual/_commonjs-dynamic-modules.js +5 -0
- package/dist/es/_virtual/browser.js +7 -0
- package/dist/es/_virtual/browser2.js +7 -0
- package/dist/es/_virtual/debug.js +7 -0
- package/dist/es/_virtual/event.js +7 -0
- package/dist/es/_virtual/http-parser.js +3 -0
- package/dist/es/_virtual/iframe.js +7 -0
- package/dist/es/_virtual/index.js +7 -0
- package/dist/es/_virtual/index2.js +7 -0
- package/dist/es/_virtual/index3.js +7 -0
- package/dist/es/_virtual/index4.js +7 -0
- package/dist/es/_virtual/index5.js +7 -0
- package/dist/es/_virtual/index6.js +7 -0
- package/dist/es/_virtual/index7.js +3 -0
- package/dist/es/_virtual/index8.js +7 -0
- package/dist/es/_virtual/index9.js +7 -0
- package/dist/es/_virtual/inherits.js +7 -0
- package/dist/es/_virtual/inherits_browser.js +7 -0
- package/dist/es/_virtual/json3.js +7 -0
- package/dist/es/_virtual/node.js +7 -0
- package/dist/es/_virtual/node2.js +7 -0
- package/dist/es/_virtual/stomp-node.js +3 -0
- package/dist/es/_virtual/stomp.js +3 -0
- package/dist/es/_virtual/streams.js +3 -0
- package/dist/es/_virtual/utils.js +3 -0
- package/dist/es/constants.d.ts +5 -1
- package/dist/es/constants.js +5 -1
- package/dist/es/node_modules/bufferutil/fallback.js +43 -0
- package/dist/es/node_modules/bufferutil/index.js +21 -0
- package/dist/es/node_modules/debug/src/browser.js +192 -0
- package/dist/es/node_modules/debug/src/common.js +259 -0
- package/dist/es/node_modules/debug/src/index.js +25 -0
- package/dist/es/node_modules/debug/src/node.js +192 -0
- package/dist/es/node_modules/eventsource/lib/eventsource.js +493 -0
- package/dist/es/node_modules/faye-websocket/lib/faye/eventsource.js +150 -0
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api/event.js +31 -0
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api/event_target.js +41 -0
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket/api.js +205 -0
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket/client.js +107 -0
- package/dist/es/node_modules/faye-websocket/lib/faye/websocket.js +47 -0
- package/dist/es/node_modules/has-flag/index.js +17 -0
- package/dist/es/node_modules/http-parser-js/http-parser.js +471 -0
- package/dist/es/node_modules/inherits/inherits.js +14 -0
- package/dist/es/node_modules/inherits/inherits_browser.js +38 -0
- package/dist/es/node_modules/is-typedarray/index.js +51 -0
- package/dist/es/node_modules/json3/lib/json3.js +937 -0
- package/dist/es/node_modules/ms/index.js +172 -0
- package/dist/es/node_modules/node-gyp-build/index.js +21 -0
- package/dist/es/node_modules/node-gyp-build/node-gyp-build.js +222 -0
- package/dist/es/node_modules/querystringify/index.js +120 -0
- package/dist/es/node_modules/requires-port/index.js +38 -0
- package/dist/es/node_modules/safe-buffer/index.js +71 -0
- package/dist/es/node_modules/supports-color/index.js +143 -0
- package/dist/es/node_modules/typedarray-to-buffer/index.js +37 -0
- package/dist/es/node_modules/url-parse/index.js +594 -0
- package/dist/es/node_modules/utf-8-validate/fallback.js +71 -0
- package/dist/es/node_modules/utf-8-validate/index.js +21 -0
- package/dist/es/node_modules/websocket/index.js +15 -0
- package/dist/es/node_modules/websocket/lib/Deprecation.js +42 -0
- package/dist/es/node_modules/websocket/lib/W3CWebSocket.js +268 -0
- package/dist/es/node_modules/websocket/lib/WebSocketClient.js +380 -0
- package/dist/es/node_modules/websocket/lib/WebSocketConnection.js +914 -0
- package/dist/es/node_modules/websocket/lib/WebSocketFrame.js +293 -0
- package/dist/es/node_modules/websocket/lib/WebSocketRequest.js +543 -0
- package/dist/es/node_modules/websocket/lib/WebSocketRouter.js +172 -0
- package/dist/es/node_modules/websocket/lib/WebSocketRouterRequest.js +67 -0
- package/dist/es/node_modules/websocket/lib/WebSocketServer.js +272 -0
- package/dist/es/node_modules/websocket/lib/utils.js +80 -0
- package/dist/es/node_modules/websocket/lib/version.js +13 -0
- package/dist/es/node_modules/websocket/lib/websocket.js +31 -0
- package/dist/es/node_modules/websocket/node_modules/debug/src/browser.js +199 -0
- package/dist/es/node_modules/websocket/node_modules/debug/src/debug.js +215 -0
- package/dist/es/node_modules/websocket/node_modules/debug/src/index.js +25 -0
- package/dist/es/node_modules/websocket/node_modules/debug/src/node.js +266 -0
- package/dist/es/node_modules/websocket/node_modules/ms/index.js +162 -0
- package/dist/es/node_modules/websocket/package.json.js +77 -0
- package/dist/es/node_modules/websocket/vendor/FastBufferList.js +205 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/base.js +202 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/client.js +152 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/draft75.js +128 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/draft76.js +124 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/headers.js +44 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi/frame.js +21 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi/message.js +37 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/hybi.js +492 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/proxy.js +108 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/server.js +119 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver/stream_reader.js +72 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/driver.js +47 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/http_parser.js +140 -0
- package/dist/es/node_modules/websocket-driver/lib/websocket/streams.js +150 -0
- package/dist/es/node_modules/websocket-extensions/lib/parser.js +103 -0
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/cell.js +56 -0
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/functor.js +74 -0
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/index.js +50 -0
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/pledge.js +39 -0
- package/dist/es/node_modules/websocket-extensions/lib/pipeline/ring_buffer.js +66 -0
- package/dist/es/node_modules/websocket-extensions/lib/websocket_extensions.js +165 -0
- package/dist/es/node_modules/yaeti/index.js +17 -0
- package/dist/es/node_modules/yaeti/lib/Event.js +24 -0
- package/dist/es/node_modules/yaeti/lib/EventTarget.js +130 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/entry.js +14 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/event/close.js +21 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/event/event.js +22 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/event/eventtarget.js +62 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/event/trans-message.js +19 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/facade.js +40 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/iframe-bootstrap.js +122 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/info-ajax.js +57 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/info-iframe-receiver.js +50 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/info-iframe.js +81 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/info-receiver.js +101 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/location.js +12 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/main.js +413 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/shims.js +449 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/driver/websocket.js +5 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/driver/xhr.js +80 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/eventsource.js +34 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/htmlfile.js +31 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/iframe.js +154 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/jsonp-polling.js +41 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/ajax-based.js +55 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/buffered-sender.js +92 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/iframe-wrap.js +39 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/polling.js +65 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/lib/sender-receiver.js +52 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/eventsource.js +69 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/htmlfile.js +96 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/jsonp.js +193 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/receiver/xhr.js +75 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/jsonp.js +104 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xdr.js +113 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-cors.js +19 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-fake.js +28 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/sender/xhr-local.js +21 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/websocket.js +108 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/xdr-polling.js +30 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/xdr-streaming.js +38 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/xhr-polling.js +40 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport/xhr-streaming.js +50 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/transport-list.js +28 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/browser.js +29 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/escape.js +53 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/event.js +78 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/iframe.js +205 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/log.js +20 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/object.js +24 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/random.js +30 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/transport.js +52 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/utils/url.js +54 -0
- package/dist/es/node_modules/zt-sockjs-client/lib/version.js +11 -0
- package/dist/es/node_modules/zt-stompjs/index.js +23 -0
- package/dist/es/node_modules/zt-stompjs/lib/stomp-node.js +117 -0
- package/dist/es/node_modules/zt-stompjs/lib/stomp.js +536 -0
- package/dist/es/stompClient.d.ts +55 -0
- package/dist/es/stompClient.js +379 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +6 -2
- package/src/constants.ts +5 -0
- package/src/index.ts +4 -0
- package/src/stompClient.ts +449 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import { __exports as httpParser } from '../../_virtual/http-parser.js';
|
|
2
|
+
|
|
3
|
+
/*jshint node:true */
|
|
4
|
+
httpParser.HTTPParser = HTTPParser;
|
|
5
|
+
function HTTPParser(type) {
|
|
6
|
+
if (type !== undefined && type !== HTTPParser.REQUEST && type !== HTTPParser.RESPONSE) {
|
|
7
|
+
throw new Error('type must be REQUEST or RESPONSE');
|
|
8
|
+
}
|
|
9
|
+
if (type === undefined) ; else {
|
|
10
|
+
this.initialize(type);
|
|
11
|
+
}
|
|
12
|
+
this.maxHeaderSize=HTTPParser.maxHeaderSize;
|
|
13
|
+
}
|
|
14
|
+
HTTPParser.prototype.initialize = function (type, async_resource) {
|
|
15
|
+
if (type !== HTTPParser.REQUEST && type !== HTTPParser.RESPONSE) {
|
|
16
|
+
throw new Error('type must be REQUEST or RESPONSE');
|
|
17
|
+
}
|
|
18
|
+
this.type = type;
|
|
19
|
+
this.state = type + '_LINE';
|
|
20
|
+
this.info = {
|
|
21
|
+
headers: [],
|
|
22
|
+
upgrade: false
|
|
23
|
+
};
|
|
24
|
+
this.trailers = [];
|
|
25
|
+
this.line = '';
|
|
26
|
+
this.isChunked = false;
|
|
27
|
+
this.connection = '';
|
|
28
|
+
this.headerSize = 0; // for preventing too big headers
|
|
29
|
+
this.body_bytes = null;
|
|
30
|
+
this.isUserCall = false;
|
|
31
|
+
this.hadError = false;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
HTTPParser.encoding = 'ascii';
|
|
35
|
+
HTTPParser.maxHeaderSize = 80 * 1024; // maxHeaderSize (in bytes) is configurable, but 80kb by default;
|
|
36
|
+
HTTPParser.REQUEST = 'REQUEST';
|
|
37
|
+
HTTPParser.RESPONSE = 'RESPONSE';
|
|
38
|
+
|
|
39
|
+
// Note: *not* starting with kOnHeaders=0 line the Node parser, because any
|
|
40
|
+
// newly added constants (kOnTimeout in Node v12.19.0) will overwrite 0!
|
|
41
|
+
var kOnHeaders = HTTPParser.kOnHeaders = 1;
|
|
42
|
+
var kOnHeadersComplete = HTTPParser.kOnHeadersComplete = 2;
|
|
43
|
+
var kOnBody = HTTPParser.kOnBody = 3;
|
|
44
|
+
var kOnMessageComplete = HTTPParser.kOnMessageComplete = 4;
|
|
45
|
+
|
|
46
|
+
// Some handler stubs, needed for compatibility
|
|
47
|
+
HTTPParser.prototype[kOnHeaders] =
|
|
48
|
+
HTTPParser.prototype[kOnHeadersComplete] =
|
|
49
|
+
HTTPParser.prototype[kOnBody] =
|
|
50
|
+
HTTPParser.prototype[kOnMessageComplete] = function () {};
|
|
51
|
+
|
|
52
|
+
var compatMode0_12 = true;
|
|
53
|
+
Object.defineProperty(HTTPParser, 'kOnExecute', {
|
|
54
|
+
get: function () {
|
|
55
|
+
// hack for backward compatibility
|
|
56
|
+
compatMode0_12 = false;
|
|
57
|
+
return 99;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
var methods = httpParser.methods = HTTPParser.methods = [
|
|
62
|
+
'DELETE',
|
|
63
|
+
'GET',
|
|
64
|
+
'HEAD',
|
|
65
|
+
'POST',
|
|
66
|
+
'PUT',
|
|
67
|
+
'CONNECT',
|
|
68
|
+
'OPTIONS',
|
|
69
|
+
'TRACE',
|
|
70
|
+
'COPY',
|
|
71
|
+
'LOCK',
|
|
72
|
+
'MKCOL',
|
|
73
|
+
'MOVE',
|
|
74
|
+
'PROPFIND',
|
|
75
|
+
'PROPPATCH',
|
|
76
|
+
'SEARCH',
|
|
77
|
+
'UNLOCK',
|
|
78
|
+
'BIND',
|
|
79
|
+
'REBIND',
|
|
80
|
+
'UNBIND',
|
|
81
|
+
'ACL',
|
|
82
|
+
'REPORT',
|
|
83
|
+
'MKACTIVITY',
|
|
84
|
+
'CHECKOUT',
|
|
85
|
+
'MERGE',
|
|
86
|
+
'M-SEARCH',
|
|
87
|
+
'NOTIFY',
|
|
88
|
+
'SUBSCRIBE',
|
|
89
|
+
'UNSUBSCRIBE',
|
|
90
|
+
'PATCH',
|
|
91
|
+
'PURGE',
|
|
92
|
+
'MKCALENDAR',
|
|
93
|
+
'LINK',
|
|
94
|
+
'UNLINK',
|
|
95
|
+
'SOURCE',
|
|
96
|
+
];
|
|
97
|
+
var method_connect = methods.indexOf('CONNECT');
|
|
98
|
+
HTTPParser.prototype.reinitialize = HTTPParser;
|
|
99
|
+
HTTPParser.prototype.close =
|
|
100
|
+
HTTPParser.prototype.pause =
|
|
101
|
+
HTTPParser.prototype.resume =
|
|
102
|
+
HTTPParser.prototype.remove =
|
|
103
|
+
HTTPParser.prototype.free = function () {};
|
|
104
|
+
HTTPParser.prototype._compatMode0_11 = false;
|
|
105
|
+
HTTPParser.prototype.getAsyncId = function() { return 0; };
|
|
106
|
+
|
|
107
|
+
var headerState = {
|
|
108
|
+
REQUEST_LINE: true,
|
|
109
|
+
RESPONSE_LINE: true,
|
|
110
|
+
HEADER: true
|
|
111
|
+
};
|
|
112
|
+
HTTPParser.prototype.execute = function (chunk, start, length) {
|
|
113
|
+
if (!(this instanceof HTTPParser)) {
|
|
114
|
+
throw new TypeError('not a HTTPParser');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// backward compat to node < 0.11.4
|
|
118
|
+
// Note: the start and length params were removed in newer version
|
|
119
|
+
start = start || 0;
|
|
120
|
+
length = typeof length === 'number' ? length : chunk.length;
|
|
121
|
+
|
|
122
|
+
this.chunk = chunk;
|
|
123
|
+
this.offset = start;
|
|
124
|
+
var end = this.end = start + length;
|
|
125
|
+
try {
|
|
126
|
+
while (this.offset < end) {
|
|
127
|
+
if (this[this.state]()) {
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} catch (err) {
|
|
132
|
+
if (this.isUserCall) {
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
this.hadError = true;
|
|
136
|
+
return err;
|
|
137
|
+
}
|
|
138
|
+
this.chunk = null;
|
|
139
|
+
length = this.offset - start;
|
|
140
|
+
if (headerState[this.state]) {
|
|
141
|
+
this.headerSize += length;
|
|
142
|
+
if (this.headerSize > (this.maxHeaderSize||HTTPParser.maxHeaderSize)) {
|
|
143
|
+
return new Error('max header size exceeded');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return length;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
var stateFinishAllowed = {
|
|
150
|
+
REQUEST_LINE: true,
|
|
151
|
+
RESPONSE_LINE: true,
|
|
152
|
+
BODY_RAW: true
|
|
153
|
+
};
|
|
154
|
+
HTTPParser.prototype.finish = function () {
|
|
155
|
+
if (this.hadError) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (!stateFinishAllowed[this.state]) {
|
|
159
|
+
return new Error('invalid state for EOF');
|
|
160
|
+
}
|
|
161
|
+
if (this.state === 'BODY_RAW') {
|
|
162
|
+
this.userCall()(this[kOnMessageComplete]());
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// These three methods are used for an internal speed optimization, and it also
|
|
167
|
+
// works if theses are noops. Basically consume() asks us to read the bytes
|
|
168
|
+
// ourselves, but if we don't do it we get them through execute().
|
|
169
|
+
HTTPParser.prototype.consume =
|
|
170
|
+
HTTPParser.prototype.unconsume =
|
|
171
|
+
HTTPParser.prototype.getCurrentBuffer = function () {};
|
|
172
|
+
|
|
173
|
+
//For correct error handling - see HTTPParser#execute
|
|
174
|
+
//Usage: this.userCall()(userFunction('arg'));
|
|
175
|
+
HTTPParser.prototype.userCall = function () {
|
|
176
|
+
this.isUserCall = true;
|
|
177
|
+
var self = this;
|
|
178
|
+
return function (ret) {
|
|
179
|
+
self.isUserCall = false;
|
|
180
|
+
return ret;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
HTTPParser.prototype.nextRequest = function () {
|
|
185
|
+
this.userCall()(this[kOnMessageComplete]());
|
|
186
|
+
this.reinitialize(this.type);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
HTTPParser.prototype.consumeLine = function () {
|
|
190
|
+
var end = this.end,
|
|
191
|
+
chunk = this.chunk;
|
|
192
|
+
for (var i = this.offset; i < end; i++) {
|
|
193
|
+
if (chunk[i] === 0x0a) { // \n
|
|
194
|
+
var line = this.line + chunk.toString(HTTPParser.encoding, this.offset, i);
|
|
195
|
+
if (line.charAt(line.length - 1) === '\r') {
|
|
196
|
+
line = line.substr(0, line.length - 1);
|
|
197
|
+
}
|
|
198
|
+
this.line = '';
|
|
199
|
+
this.offset = i + 1;
|
|
200
|
+
return line;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
//line split over multiple chunks
|
|
204
|
+
this.line += chunk.toString(HTTPParser.encoding, this.offset, this.end);
|
|
205
|
+
this.offset = this.end;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
var headerExp = /^([^: \t]+):[ \t]*((?:.*[^ \t])|)/;
|
|
209
|
+
var headerContinueExp = /^[ \t]+(.*[^ \t])/;
|
|
210
|
+
HTTPParser.prototype.parseHeader = function (line, headers) {
|
|
211
|
+
if (line.indexOf('\r') !== -1) {
|
|
212
|
+
throw parseErrorCode('HPE_LF_EXPECTED');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
var match = headerExp.exec(line);
|
|
216
|
+
var k = match && match[1];
|
|
217
|
+
if (k) { // skip empty string (malformed header)
|
|
218
|
+
headers.push(k);
|
|
219
|
+
headers.push(match[2]);
|
|
220
|
+
} else {
|
|
221
|
+
var matchContinue = headerContinueExp.exec(line);
|
|
222
|
+
if (matchContinue && headers.length) {
|
|
223
|
+
if (headers[headers.length - 1]) {
|
|
224
|
+
headers[headers.length - 1] += ' ';
|
|
225
|
+
}
|
|
226
|
+
headers[headers.length - 1] += matchContinue[1];
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
var requestExp = /^([A-Z-]+) ([^ ]+) HTTP\/(\d)\.(\d)$/;
|
|
232
|
+
HTTPParser.prototype.REQUEST_LINE = function () {
|
|
233
|
+
var line = this.consumeLine();
|
|
234
|
+
if (!line) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
var match = requestExp.exec(line);
|
|
238
|
+
if (match === null) {
|
|
239
|
+
throw parseErrorCode('HPE_INVALID_CONSTANT');
|
|
240
|
+
}
|
|
241
|
+
this.info.method = this._compatMode0_11 ? match[1] : methods.indexOf(match[1]);
|
|
242
|
+
if (this.info.method === -1) {
|
|
243
|
+
throw new Error('invalid request method');
|
|
244
|
+
}
|
|
245
|
+
this.info.url = match[2];
|
|
246
|
+
this.info.versionMajor = +match[3];
|
|
247
|
+
this.info.versionMinor = +match[4];
|
|
248
|
+
this.body_bytes = 0;
|
|
249
|
+
this.state = 'HEADER';
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
var responseExp = /^HTTP\/(\d)\.(\d) (\d{3}) ?(.*)$/;
|
|
253
|
+
HTTPParser.prototype.RESPONSE_LINE = function () {
|
|
254
|
+
var line = this.consumeLine();
|
|
255
|
+
if (!line) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
var match = responseExp.exec(line);
|
|
259
|
+
if (match === null) {
|
|
260
|
+
throw parseErrorCode('HPE_INVALID_CONSTANT');
|
|
261
|
+
}
|
|
262
|
+
this.info.versionMajor = +match[1];
|
|
263
|
+
this.info.versionMinor = +match[2];
|
|
264
|
+
var statusCode = this.info.statusCode = +match[3];
|
|
265
|
+
this.info.statusMessage = match[4];
|
|
266
|
+
// Implied zero length.
|
|
267
|
+
if ((statusCode / 100 | 0) === 1 || statusCode === 204 || statusCode === 304) {
|
|
268
|
+
this.body_bytes = 0;
|
|
269
|
+
}
|
|
270
|
+
this.state = 'HEADER';
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
HTTPParser.prototype.shouldKeepAlive = function () {
|
|
274
|
+
if (this.info.versionMajor > 0 && this.info.versionMinor > 0) {
|
|
275
|
+
if (this.connection.indexOf('close') !== -1) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
} else if (this.connection.indexOf('keep-alive') === -1) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
if (this.body_bytes !== null || this.isChunked) { // || skipBody
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
return false;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
HTTPParser.prototype.HEADER = function () {
|
|
288
|
+
var line = this.consumeLine();
|
|
289
|
+
if (line === undefined) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
var info = this.info;
|
|
293
|
+
if (line) {
|
|
294
|
+
this.parseHeader(line, info.headers);
|
|
295
|
+
} else {
|
|
296
|
+
var headers = info.headers;
|
|
297
|
+
var hasContentLength = false;
|
|
298
|
+
var currentContentLengthValue;
|
|
299
|
+
var hasUpgradeHeader = false;
|
|
300
|
+
for (var i = 0; i < headers.length; i += 2) {
|
|
301
|
+
switch (headers[i].toLowerCase()) {
|
|
302
|
+
case 'transfer-encoding':
|
|
303
|
+
this.isChunked = headers[i + 1].toLowerCase() === 'chunked';
|
|
304
|
+
break;
|
|
305
|
+
case 'content-length':
|
|
306
|
+
currentContentLengthValue = +headers[i + 1];
|
|
307
|
+
if (hasContentLength) {
|
|
308
|
+
// Fix duplicate Content-Length header with same values.
|
|
309
|
+
// Throw error only if values are different.
|
|
310
|
+
// Known issues:
|
|
311
|
+
// https://github.com/request/request/issues/2091#issuecomment-328715113
|
|
312
|
+
// https://github.com/nodejs/node/issues/6517#issuecomment-216263771
|
|
313
|
+
if (currentContentLengthValue !== this.body_bytes) {
|
|
314
|
+
throw parseErrorCode('HPE_UNEXPECTED_CONTENT_LENGTH');
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
hasContentLength = true;
|
|
318
|
+
this.body_bytes = currentContentLengthValue;
|
|
319
|
+
}
|
|
320
|
+
break;
|
|
321
|
+
case 'connection':
|
|
322
|
+
this.connection += headers[i + 1].toLowerCase();
|
|
323
|
+
break;
|
|
324
|
+
case 'upgrade':
|
|
325
|
+
hasUpgradeHeader = true;
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// if both isChunked and hasContentLength, isChunked wins
|
|
331
|
+
// This is required so the body is parsed using the chunked method, and matches
|
|
332
|
+
// Chrome's behavior. We could, maybe, ignore them both (would get chunked
|
|
333
|
+
// encoding into the body), and/or disable shouldKeepAlive to be more
|
|
334
|
+
// resilient.
|
|
335
|
+
if (this.isChunked && hasContentLength) {
|
|
336
|
+
hasContentLength = false;
|
|
337
|
+
this.body_bytes = null;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Logic from https://github.com/nodejs/http-parser/blob/921d5585515a153fa00e411cf144280c59b41f90/http_parser.c#L1727-L1737
|
|
341
|
+
// "For responses, "Upgrade: foo" and "Connection: upgrade" are
|
|
342
|
+
// mandatory only when it is a 101 Switching Protocols response,
|
|
343
|
+
// otherwise it is purely informational, to announce support.
|
|
344
|
+
if (hasUpgradeHeader && this.connection.indexOf('upgrade') != -1) {
|
|
345
|
+
info.upgrade = this.type === HTTPParser.REQUEST || info.statusCode === 101;
|
|
346
|
+
} else {
|
|
347
|
+
info.upgrade = info.method === method_connect;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (this.isChunked && info.upgrade) {
|
|
351
|
+
this.isChunked = false;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
info.shouldKeepAlive = this.shouldKeepAlive();
|
|
355
|
+
//problem which also exists in original node: we should know skipBody before calling onHeadersComplete
|
|
356
|
+
var skipBody;
|
|
357
|
+
if (compatMode0_12) {
|
|
358
|
+
skipBody = this.userCall()(this[kOnHeadersComplete](info));
|
|
359
|
+
} else {
|
|
360
|
+
skipBody = this.userCall()(this[kOnHeadersComplete](info.versionMajor,
|
|
361
|
+
info.versionMinor, info.headers, info.method, info.url, info.statusCode,
|
|
362
|
+
info.statusMessage, info.upgrade, info.shouldKeepAlive));
|
|
363
|
+
}
|
|
364
|
+
if (skipBody === 2) {
|
|
365
|
+
this.nextRequest();
|
|
366
|
+
return true;
|
|
367
|
+
} else if (this.isChunked && !skipBody) {
|
|
368
|
+
this.state = 'BODY_CHUNKHEAD';
|
|
369
|
+
} else if (skipBody || this.body_bytes === 0) {
|
|
370
|
+
this.nextRequest();
|
|
371
|
+
// For older versions of node (v6.x and older?), that return skipBody=1 or skipBody=true,
|
|
372
|
+
// need this "return true;" if it's an upgrade request.
|
|
373
|
+
return info.upgrade;
|
|
374
|
+
} else if (this.body_bytes === null) {
|
|
375
|
+
this.state = 'BODY_RAW';
|
|
376
|
+
} else {
|
|
377
|
+
this.state = 'BODY_SIZED';
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
HTTPParser.prototype.BODY_CHUNKHEAD = function () {
|
|
383
|
+
var line = this.consumeLine();
|
|
384
|
+
if (line === undefined) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
this.body_bytes = parseInt(line, 16);
|
|
388
|
+
if (!this.body_bytes) {
|
|
389
|
+
this.state = 'BODY_CHUNKTRAILERS';
|
|
390
|
+
} else {
|
|
391
|
+
this.state = 'BODY_CHUNK';
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
HTTPParser.prototype.BODY_CHUNK = function () {
|
|
396
|
+
var length = Math.min(this.end - this.offset, this.body_bytes);
|
|
397
|
+
// 0, length are for backwards compatibility. See: https://github.com/creationix/http-parser-js/pull/98
|
|
398
|
+
this.userCall()(this[kOnBody](this.chunk.slice(this.offset, this.offset + length), 0, length));
|
|
399
|
+
this.offset += length;
|
|
400
|
+
this.body_bytes -= length;
|
|
401
|
+
if (!this.body_bytes) {
|
|
402
|
+
this.state = 'BODY_CHUNKEMPTYLINE';
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
HTTPParser.prototype.BODY_CHUNKEMPTYLINE = function () {
|
|
407
|
+
var line = this.consumeLine();
|
|
408
|
+
if (line === undefined) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (line !== '') {
|
|
412
|
+
throw new Error('Expected empty line');
|
|
413
|
+
}
|
|
414
|
+
this.state = 'BODY_CHUNKHEAD';
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
HTTPParser.prototype.BODY_CHUNKTRAILERS = function () {
|
|
418
|
+
var line = this.consumeLine();
|
|
419
|
+
if (line === undefined) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (line) {
|
|
423
|
+
this.parseHeader(line, this.trailers);
|
|
424
|
+
} else {
|
|
425
|
+
if (this.trailers.length) {
|
|
426
|
+
this.userCall()(this[kOnHeaders](this.trailers, ''));
|
|
427
|
+
}
|
|
428
|
+
this.nextRequest();
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
HTTPParser.prototype.BODY_RAW = function () {
|
|
433
|
+
// 0, length are for backwards compatibility. See: https://github.com/creationix/http-parser-js/pull/98
|
|
434
|
+
this.userCall()(this[kOnBody](this.chunk.slice(this.offset, this.end), 0, this.end - this.offset));
|
|
435
|
+
this.offset = this.end;
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
HTTPParser.prototype.BODY_SIZED = function () {
|
|
439
|
+
var length = Math.min(this.end - this.offset, this.body_bytes);
|
|
440
|
+
// 0, length are for backwards compatibility. See: https://github.com/creationix/http-parser-js/pull/98
|
|
441
|
+
this.userCall()(this[kOnBody](this.chunk.slice(this.offset, this.offset + length), 0, length));
|
|
442
|
+
this.offset += length;
|
|
443
|
+
this.body_bytes -= length;
|
|
444
|
+
if (!this.body_bytes) {
|
|
445
|
+
this.nextRequest();
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
// backward compat to node < 0.11.6
|
|
450
|
+
['Headers', 'HeadersComplete', 'Body', 'MessageComplete'].forEach(function (name) {
|
|
451
|
+
var k = HTTPParser['kOn' + name];
|
|
452
|
+
Object.defineProperty(HTTPParser.prototype, 'on' + name, {
|
|
453
|
+
get: function () {
|
|
454
|
+
return this[k];
|
|
455
|
+
},
|
|
456
|
+
set: function (to) {
|
|
457
|
+
// hack for backward compatibility
|
|
458
|
+
this._compatMode0_11 = true;
|
|
459
|
+
method_connect = 'CONNECT';
|
|
460
|
+
return (this[k] = to);
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
function parseErrorCode(code) {
|
|
466
|
+
var err = new Error('Parse Error');
|
|
467
|
+
err.code = code;
|
|
468
|
+
return err;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export { httpParser as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __module as inherits } from '../../_virtual/inherits.js';
|
|
2
|
+
import { __require as requireInherits_browser } from './inherits_browser.js';
|
|
3
|
+
|
|
4
|
+
(function (module) {
|
|
5
|
+
try {
|
|
6
|
+
var util = require('util');
|
|
7
|
+
/* istanbul ignore next */
|
|
8
|
+
if (typeof util.inherits !== 'function') throw '';
|
|
9
|
+
module.exports = util.inherits;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
/* istanbul ignore next */
|
|
12
|
+
module.exports = requireInherits_browser();
|
|
13
|
+
}
|
|
14
|
+
} (inherits));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { exports as inherits_browserExports, __module as inherits_browser } from '../../_virtual/inherits_browser.js';
|
|
2
|
+
|
|
3
|
+
var hasRequiredInherits_browser;
|
|
4
|
+
|
|
5
|
+
function requireInherits_browser () {
|
|
6
|
+
if (hasRequiredInherits_browser) return inherits_browserExports;
|
|
7
|
+
hasRequiredInherits_browser = 1;
|
|
8
|
+
if (typeof Object.create === 'function') {
|
|
9
|
+
// implementation from standard node.js 'util' module
|
|
10
|
+
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
11
|
+
if (superCtor) {
|
|
12
|
+
ctor.super_ = superCtor;
|
|
13
|
+
ctor.prototype = Object.create(superCtor.prototype, {
|
|
14
|
+
constructor: {
|
|
15
|
+
value: ctor,
|
|
16
|
+
enumerable: false,
|
|
17
|
+
writable: true,
|
|
18
|
+
configurable: true
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
} else {
|
|
24
|
+
// old school shim for old browsers
|
|
25
|
+
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
26
|
+
if (superCtor) {
|
|
27
|
+
ctor.super_ = superCtor;
|
|
28
|
+
var TempCtor = function () {};
|
|
29
|
+
TempCtor.prototype = superCtor.prototype;
|
|
30
|
+
ctor.prototype = new TempCtor();
|
|
31
|
+
ctor.prototype.constructor = ctor;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return inherits_browserExports;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { requireInherits_browser as __require };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var isTypedarray;
|
|
2
|
+
var hasRequiredIsTypedarray;
|
|
3
|
+
|
|
4
|
+
function requireIsTypedarray () {
|
|
5
|
+
if (hasRequiredIsTypedarray) return isTypedarray;
|
|
6
|
+
hasRequiredIsTypedarray = 1;
|
|
7
|
+
isTypedarray = isTypedArray;
|
|
8
|
+
isTypedArray.strict = isStrictTypedArray;
|
|
9
|
+
isTypedArray.loose = isLooseTypedArray;
|
|
10
|
+
|
|
11
|
+
var toString = Object.prototype.toString;
|
|
12
|
+
var names = {
|
|
13
|
+
'[object Int8Array]': true
|
|
14
|
+
, '[object Int16Array]': true
|
|
15
|
+
, '[object Int32Array]': true
|
|
16
|
+
, '[object Uint8Array]': true
|
|
17
|
+
, '[object Uint8ClampedArray]': true
|
|
18
|
+
, '[object Uint16Array]': true
|
|
19
|
+
, '[object Uint32Array]': true
|
|
20
|
+
, '[object Float32Array]': true
|
|
21
|
+
, '[object Float64Array]': true
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function isTypedArray(arr) {
|
|
25
|
+
return (
|
|
26
|
+
isStrictTypedArray(arr)
|
|
27
|
+
|| isLooseTypedArray(arr)
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isStrictTypedArray(arr) {
|
|
32
|
+
return (
|
|
33
|
+
arr instanceof Int8Array
|
|
34
|
+
|| arr instanceof Int16Array
|
|
35
|
+
|| arr instanceof Int32Array
|
|
36
|
+
|| arr instanceof Uint8Array
|
|
37
|
+
|| arr instanceof Uint8ClampedArray
|
|
38
|
+
|| arr instanceof Uint16Array
|
|
39
|
+
|| arr instanceof Uint32Array
|
|
40
|
+
|| arr instanceof Float32Array
|
|
41
|
+
|| arr instanceof Float64Array
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isLooseTypedArray(arr) {
|
|
46
|
+
return names[toString.call(arr)]
|
|
47
|
+
}
|
|
48
|
+
return isTypedarray;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { requireIsTypedarray as __require };
|