@loaders.gl/polyfills 3.4.14 → 3.4.15
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/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +11 -12
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/encoding.js +12 -13
- package/dist/es5/lib/encoding.js.map +1 -1
- package/dist/es5/node/buffer/to-array-buffer.node.js +1 -1
- package/dist/es5/node/buffer/to-array-buffer.node.js.map +1 -1
- package/dist/es5/node/fetch/fetch-file.node.js +34 -59
- package/dist/es5/node/fetch/fetch-file.node.js.map +1 -1
- package/dist/es5/node/fetch/fetch.node.js +75 -135
- package/dist/es5/node/fetch/fetch.node.js.map +1 -1
- package/dist/es5/node/fetch/headers.node.js +63 -104
- package/dist/es5/node/fetch/headers.node.js.map +1 -1
- package/dist/es5/node/fetch/response.node.js +40 -147
- package/dist/es5/node/fetch/response.node.js.map +1 -1
- package/dist/es5/node/fetch/utils/decode-data-uri.node.js +10 -16
- package/dist/es5/node/fetch/utils/decode-data-uri.node.js.map +1 -1
- package/dist/es5/node/fetch/utils/stream-utils.node.js +22 -62
- package/dist/es5/node/fetch/utils/stream-utils.node.js.map +1 -1
- package/dist/es5/node/file/blob-stream-controller.js +33 -71
- package/dist/es5/node/file/blob-stream-controller.js.map +1 -1
- package/dist/es5/node/file/blob-stream.js +12 -48
- package/dist/es5/node/file/blob-stream.js.map +1 -1
- package/dist/es5/node/file/blob.js +98 -182
- package/dist/es5/node/file/blob.js.map +1 -1
- package/dist/es5/node/file/file-reader.js +39 -124
- package/dist/es5/node/file/file-reader.js.map +1 -1
- package/dist/es5/node/file/file.js +14 -31
- package/dist/es5/node/file/file.js.map +1 -1
- package/dist/es5/node/file/readable-stream.js +1 -17
- package/dist/es5/node/file/readable-stream.js.map +1 -1
- package/dist/es5/node/images/encode-image.node.js +8 -10
- package/dist/es5/node/images/encode-image.node.js.map +1 -1
- package/dist/es5/node/images/parse-image.node.js +23 -49
- package/dist/es5/node/images/parse-image.node.js.map +1 -1
- package/dist/es5/promise/all-settled.js +7 -7
- package/dist/es5/promise/all-settled.js.map +1 -1
- package/dist/es5/utils/globals.js +3 -5
- package/dist/es5/utils/globals.js.map +1 -1
- package/package.json +2 -2
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.bufferToArrayBuffer = bufferToArrayBuffer;
|
|
7
7
|
function bufferToArrayBuffer(buffer) {
|
|
8
8
|
if (Buffer.isBuffer(buffer)) {
|
|
9
|
-
|
|
9
|
+
const typedArray = new Uint8Array(buffer);
|
|
10
10
|
return typedArray.buffer;
|
|
11
11
|
}
|
|
12
12
|
return buffer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-array-buffer.node.js","names":["bufferToArrayBuffer","buffer","Buffer","isBuffer","typedArray","Uint8Array"],"sources":["../../../../src/node/buffer/to-array-buffer.node.ts"],"sourcesContent":["export function bufferToArrayBuffer(buffer) {\n // TODO - per docs we should just be able to call buffer.buffer, but there are issues\n if (Buffer.isBuffer(buffer)) {\n const typedArray = new Uint8Array(buffer);\n return typedArray.buffer;\n }\n return buffer;\n}\n"],"mappings":";;;;;;AAAO,SAASA,mBAAmBA,CAACC,MAAM,EAAE;EAE1C,IAAIC,MAAM,CAACC,QAAQ,CAACF,MAAM,CAAC,EAAE;IAC3B,
|
|
1
|
+
{"version":3,"file":"to-array-buffer.node.js","names":["bufferToArrayBuffer","buffer","Buffer","isBuffer","typedArray","Uint8Array"],"sources":["../../../../src/node/buffer/to-array-buffer.node.ts"],"sourcesContent":["export function bufferToArrayBuffer(buffer) {\n // TODO - per docs we should just be able to call buffer.buffer, but there are issues\n if (Buffer.isBuffer(buffer)) {\n const typedArray = new Uint8Array(buffer);\n return typedArray.buffer;\n }\n return buffer;\n}\n"],"mappings":";;;;;;AAAO,SAASA,mBAAmBA,CAACC,MAAM,EAAE;EAE1C,IAAIC,MAAM,CAACC,QAAQ,CAACF,MAAM,CAAC,EAAE;IAC3B,MAAMG,UAAU,GAAG,IAAIC,UAAU,CAACJ,MAAM,CAAC;IACzC,OAAOG,UAAU,CAACH,MAAM;EAC1B;EACA,OAAOA,MAAM;AACf"}
|
|
@@ -6,78 +6,53 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.fetchFileNode = fetchFileNode;
|
|
8
8
|
exports.isRequestURL = isRequestURL;
|
|
9
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
9
|
var _fs = _interopRequireDefault(require("fs"));
|
|
12
10
|
var _response = require("./response.node");
|
|
13
|
-
var
|
|
11
|
+
var _headers = require("./headers.node");
|
|
14
12
|
function isRequestURL(url) {
|
|
15
13
|
return url.startsWith('http:') || url.startsWith('https:');
|
|
16
14
|
}
|
|
17
|
-
function fetchFileNode(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
status: status,
|
|
48
|
-
statusText: statusText,
|
|
49
|
-
url: url
|
|
50
|
-
}));
|
|
51
|
-
case 11:
|
|
52
|
-
_context.prev = 11;
|
|
53
|
-
_context.t0 = _context["catch"](1);
|
|
54
|
-
_status = 400;
|
|
55
|
-
_statusText = _context.t0.message;
|
|
56
|
-
_headers = {};
|
|
57
|
-
return _context.abrupt("return", new _response.Response(_context.t0.message, {
|
|
58
|
-
headers: _headers,
|
|
59
|
-
status: _status,
|
|
60
|
-
statusText: _statusText,
|
|
61
|
-
url: url
|
|
62
|
-
}));
|
|
63
|
-
case 17:
|
|
64
|
-
case "end":
|
|
65
|
-
return _context.stop();
|
|
66
|
-
}
|
|
67
|
-
}, _callee, null, [[1, 11]]);
|
|
68
|
-
}));
|
|
69
|
-
return _fetchFileNode.apply(this, arguments);
|
|
15
|
+
async function fetchFileNode(url, options) {
|
|
16
|
+
const noqueryUrl = url.split('?')[0];
|
|
17
|
+
try {
|
|
18
|
+
const body = await new Promise((resolve, reject) => {
|
|
19
|
+
const stream = _fs.default.createReadStream(noqueryUrl, {
|
|
20
|
+
encoding: null
|
|
21
|
+
});
|
|
22
|
+
stream.once('readable', () => resolve(stream));
|
|
23
|
+
stream.on('error', error => reject(error));
|
|
24
|
+
});
|
|
25
|
+
const status = 200;
|
|
26
|
+
const statusText = 'OK';
|
|
27
|
+
const headers = getHeadersForFile(noqueryUrl);
|
|
28
|
+
return new _response.Response(body, {
|
|
29
|
+
headers,
|
|
30
|
+
status,
|
|
31
|
+
statusText,
|
|
32
|
+
url
|
|
33
|
+
});
|
|
34
|
+
} catch (error) {
|
|
35
|
+
const status = 400;
|
|
36
|
+
const statusText = error.message;
|
|
37
|
+
const headers = {};
|
|
38
|
+
return new _response.Response(error.message, {
|
|
39
|
+
headers,
|
|
40
|
+
status,
|
|
41
|
+
statusText,
|
|
42
|
+
url
|
|
43
|
+
});
|
|
44
|
+
}
|
|
70
45
|
}
|
|
71
46
|
function getHeadersForFile(noqueryUrl) {
|
|
72
|
-
|
|
47
|
+
const headers = {};
|
|
73
48
|
if (!headers['content-length']) {
|
|
74
|
-
|
|
49
|
+
const stats = _fs.default.statSync(noqueryUrl);
|
|
75
50
|
headers['content-length'] = stats.size;
|
|
76
51
|
}
|
|
77
52
|
if (noqueryUrl.endsWith('.gz')) {
|
|
78
53
|
noqueryUrl = noqueryUrl.slice(0, -3);
|
|
79
54
|
headers['content-encoding'] = 'gzip';
|
|
80
55
|
}
|
|
81
|
-
return new
|
|
56
|
+
return new _headers.Headers(headers);
|
|
82
57
|
}
|
|
83
58
|
//# sourceMappingURL=fetch-file.node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-file.node.js","names":["_fs","_interopRequireDefault","require","_response","
|
|
1
|
+
{"version":3,"file":"fetch-file.node.js","names":["_fs","_interopRequireDefault","require","_response","_headers","isRequestURL","url","startsWith","fetchFileNode","options","noqueryUrl","split","body","Promise","resolve","reject","stream","fs","createReadStream","encoding","once","on","error","status","statusText","headers","getHeadersForFile","Response","message","stats","statSync","size","endsWith","slice","Headers"],"sources":["../../../../src/node/fetch/fetch-file.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport fs from 'fs'; // `fs` will be empty object in browsers (see package.json \"browser\" field).\nimport {Response} from './response.node';\nimport {Headers} from './headers.node';\n\nexport function isRequestURL(url: string): boolean {\n return url.startsWith('http:') || url.startsWith('https:');\n}\n\nexport async function fetchFileNode(url: string, options): Promise<Response> {\n const noqueryUrl = url.split('?')[0];\n\n try {\n // Now open the stream\n const body = await new Promise((resolve, reject) => {\n // @ts-ignore\n const stream = fs.createReadStream(noqueryUrl, {encoding: null});\n stream.once('readable', () => resolve(stream));\n stream.on('error', (error) => reject(error));\n });\n\n const status = 200;\n const statusText = 'OK';\n const headers = getHeadersForFile(noqueryUrl);\n return new Response(body, {headers, status, statusText, url});\n } catch (error) {\n const status = 400;\n const statusText = (error as Error).message;\n const headers = {};\n return new Response((error as Error).message, {headers, status, statusText, url});\n }\n}\n\nfunction getHeadersForFile(noqueryUrl: string): Headers {\n const headers = {};\n\n // Fix up content length if we can for best progress experience\n if (!headers['content-length']) {\n const stats = fs.statSync(noqueryUrl);\n headers['content-length'] = stats.size;\n }\n\n // Automatically decompress gzipped files with .gz extension\n if (noqueryUrl.endsWith('.gz')) {\n noqueryUrl = noqueryUrl.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,OAAO,IAAIE,kBAAQ,CAAEL,KAAK,CAAWM,OAAO,EAAE;MAACH,OAAO;MAAEF,MAAM;MAAEC,UAAU;MAAElB;IAAG,CAAC,CAAC;EACnF;AACF;AAEA,SAASoB,iBAAiBA,CAAChB,UAAkB,EAAW;EACtD,MAAMe,OAAO,GAAG,CAAC,CAAC;EAGlB,IAAI,CAACA,OAAO,CAAC,gBAAgB,CAAC,EAAE;IAC9B,MAAMI,KAAK,GAAGZ,WAAE,CAACa,QAAQ,CAACpB,UAAU,CAAC;IACrCe,OAAO,CAAC,gBAAgB,CAAC,GAAGI,KAAK,CAACE,IAAI;EACxC;EAGA,IAAIrB,UAAU,CAACsB,QAAQ,CAAC,KAAK,CAAC,EAAE;IAC9BtB,UAAU,GAAGA,UAAU,CAACuB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpCR,OAAO,CAAC,kBAAkB,CAAC,GAAG,MAAM;EACtC;EAEA,OAAO,IAAIS,gBAAO,CAACT,OAAO,CAAC;AAC7B"}
|
|
@@ -6,156 +6,96 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createHTTPRequestReadStream = createHTTPRequestReadStream;
|
|
8
8
|
exports.fetchNode = fetchNode;
|
|
9
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
9
|
var _http = _interopRequireDefault(require("http"));
|
|
13
10
|
var _https = _interopRequireDefault(require("https"));
|
|
14
11
|
var _response = require("./response.node");
|
|
15
12
|
var _headers = require("./headers.node");
|
|
16
|
-
var
|
|
13
|
+
var _decodeDataUri = require("./utils/decode-data-uri.node");
|
|
17
14
|
var _fetchFile = require("./fetch-file.node");
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
headers = getHeaders(url, body, syntheticResponseHeaders);
|
|
69
|
-
_getStatus = getStatus(body), status = _getStatus.status, statusText = _getStatus.statusText;
|
|
70
|
-
followRedirect = !options || options.followRedirect || options.followRedirect === undefined;
|
|
71
|
-
if (!(status >= 300 && status < 400 && headers.has('location') && followRedirect)) {
|
|
72
|
-
_context.next = 23;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
redirectUrl = generateRedirectUrl(url, headers.get('location'));
|
|
76
|
-
_context.next = 22;
|
|
77
|
-
return fetchNode(redirectUrl, options);
|
|
78
|
-
case 22:
|
|
79
|
-
return _context.abrupt("return", _context.sent);
|
|
80
|
-
case 23:
|
|
81
|
-
return _context.abrupt("return", new _response.Response(body, {
|
|
82
|
-
headers: headers,
|
|
83
|
-
status: status,
|
|
84
|
-
statusText: statusText,
|
|
85
|
-
url: url
|
|
86
|
-
}));
|
|
87
|
-
case 26:
|
|
88
|
-
_context.prev = 26;
|
|
89
|
-
_context.t0 = _context["catch"](0);
|
|
90
|
-
return _context.abrupt("return", new _response.Response(null, {
|
|
91
|
-
status: 400,
|
|
92
|
-
statusText: String(_context.t0),
|
|
93
|
-
url: url
|
|
94
|
-
}));
|
|
95
|
-
case 29:
|
|
96
|
-
case "end":
|
|
97
|
-
return _context.stop();
|
|
98
|
-
}
|
|
99
|
-
}, _callee, null, [[0, 26]]);
|
|
100
|
-
}));
|
|
101
|
-
return _fetchNode.apply(this, arguments);
|
|
102
|
-
}
|
|
103
|
-
function createHTTPRequestReadStream(_x3, _x4) {
|
|
104
|
-
return _createHTTPRequestReadStream.apply(this, arguments);
|
|
15
|
+
const isDataURL = url => url.startsWith('data:');
|
|
16
|
+
const isRequestURL = url => url.startsWith('http:') || url.startsWith('https:');
|
|
17
|
+
async function fetchNode(url, options) {
|
|
18
|
+
try {
|
|
19
|
+
if (!isRequestURL(url) && !isDataURL(url)) {
|
|
20
|
+
return await (0, _fetchFile.fetchFileNode)(url, options);
|
|
21
|
+
}
|
|
22
|
+
if (isDataURL(url)) {
|
|
23
|
+
const {
|
|
24
|
+
arrayBuffer,
|
|
25
|
+
mimeType
|
|
26
|
+
} = (0, _decodeDataUri.decodeDataUri)(url);
|
|
27
|
+
const response = new _response.Response(arrayBuffer, {
|
|
28
|
+
headers: {
|
|
29
|
+
'content-type': mimeType
|
|
30
|
+
},
|
|
31
|
+
url
|
|
32
|
+
});
|
|
33
|
+
return response;
|
|
34
|
+
}
|
|
35
|
+
const syntheticResponseHeaders = {};
|
|
36
|
+
const originalUrl = url;
|
|
37
|
+
if (url.endsWith('.gz')) {
|
|
38
|
+
url = url.slice(0, -3);
|
|
39
|
+
syntheticResponseHeaders['content-encoding'] = 'gzip';
|
|
40
|
+
}
|
|
41
|
+
const body = await createHTTPRequestReadStream(originalUrl, options);
|
|
42
|
+
const headers = getHeaders(url, body, syntheticResponseHeaders);
|
|
43
|
+
const {
|
|
44
|
+
status,
|
|
45
|
+
statusText
|
|
46
|
+
} = getStatus(body);
|
|
47
|
+
const followRedirect = !options || options.followRedirect || options.followRedirect === undefined;
|
|
48
|
+
if (status >= 300 && status < 400 && headers.has('location') && followRedirect) {
|
|
49
|
+
const redirectUrl = generateRedirectUrl(url, headers.get('location'));
|
|
50
|
+
return await fetchNode(redirectUrl, options);
|
|
51
|
+
}
|
|
52
|
+
return new _response.Response(body, {
|
|
53
|
+
headers,
|
|
54
|
+
status,
|
|
55
|
+
statusText,
|
|
56
|
+
url
|
|
57
|
+
});
|
|
58
|
+
} catch (error) {
|
|
59
|
+
return new _response.Response(null, {
|
|
60
|
+
status: 400,
|
|
61
|
+
statusText: String(error),
|
|
62
|
+
url
|
|
63
|
+
});
|
|
64
|
+
}
|
|
105
65
|
}
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
var requestOptions = getRequestOptions(url, options);
|
|
114
|
-
var req = url.startsWith('https:') ? _https.default.request(requestOptions, function (res) {
|
|
115
|
-
return resolve(res);
|
|
116
|
-
}) : _http.default.request(requestOptions, function (res) {
|
|
117
|
-
return resolve(res);
|
|
118
|
-
});
|
|
119
|
-
req.on('error', function (error) {
|
|
120
|
-
return reject(error);
|
|
121
|
-
});
|
|
122
|
-
req.end();
|
|
123
|
-
});
|
|
124
|
-
case 2:
|
|
125
|
-
return _context2.abrupt("return", _context2.sent);
|
|
126
|
-
case 3:
|
|
127
|
-
case "end":
|
|
128
|
-
return _context2.stop();
|
|
129
|
-
}
|
|
130
|
-
}, _callee2);
|
|
131
|
-
}));
|
|
132
|
-
return _createHTTPRequestReadStream.apply(this, arguments);
|
|
66
|
+
async function createHTTPRequestReadStream(url, options) {
|
|
67
|
+
return await new Promise((resolve, reject) => {
|
|
68
|
+
const requestOptions = getRequestOptions(url, options);
|
|
69
|
+
const req = url.startsWith('https:') ? _https.default.request(requestOptions, res => resolve(res)) : _http.default.request(requestOptions, res => resolve(res));
|
|
70
|
+
req.on('error', error => reject(error));
|
|
71
|
+
req.end();
|
|
72
|
+
});
|
|
133
73
|
}
|
|
134
74
|
function generateRedirectUrl(originalUrl, location) {
|
|
135
75
|
if (location.startsWith('http')) {
|
|
136
76
|
return location;
|
|
137
77
|
}
|
|
138
|
-
|
|
78
|
+
const url = new URL(originalUrl);
|
|
139
79
|
url.pathname = location;
|
|
140
80
|
return url.href;
|
|
141
81
|
}
|
|
142
82
|
function getRequestOptions(url, options) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
for (
|
|
146
|
-
var key = _Object$keys[_i];
|
|
83
|
+
const originalHeaders = (options === null || options === void 0 ? void 0 : options.headers) || {};
|
|
84
|
+
const headers = {};
|
|
85
|
+
for (const key of Object.keys(originalHeaders)) {
|
|
147
86
|
headers[key.toLowerCase()] = originalHeaders[key];
|
|
148
87
|
}
|
|
149
88
|
headers['accept-encoding'] = headers['accept-encoding'] || 'gzip,br,deflate';
|
|
150
|
-
|
|
151
|
-
return
|
|
89
|
+
const urlObject = new URL(url);
|
|
90
|
+
return {
|
|
152
91
|
hostname: urlObject.hostname,
|
|
153
92
|
path: urlObject.pathname,
|
|
154
|
-
method: 'GET'
|
|
155
|
-
|
|
156
|
-
|
|
93
|
+
method: 'GET',
|
|
94
|
+
...options,
|
|
95
|
+
...(options === null || options === void 0 ? void 0 : options.fetch),
|
|
96
|
+
headers,
|
|
157
97
|
port: urlObject.port
|
|
158
|
-
}
|
|
98
|
+
};
|
|
159
99
|
}
|
|
160
100
|
function getStatus(httpResponse) {
|
|
161
101
|
if (httpResponse.statusCode) {
|
|
@@ -170,17 +110,17 @@ function getStatus(httpResponse) {
|
|
|
170
110
|
};
|
|
171
111
|
}
|
|
172
112
|
function getHeaders(url, httpResponse) {
|
|
173
|
-
|
|
174
|
-
|
|
113
|
+
let additionalHeaders = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
114
|
+
const headers = {};
|
|
175
115
|
if (httpResponse && httpResponse.headers) {
|
|
176
|
-
|
|
177
|
-
for (
|
|
178
|
-
|
|
116
|
+
const httpHeaders = httpResponse.headers;
|
|
117
|
+
for (const key in httpHeaders) {
|
|
118
|
+
const header = httpHeaders[key];
|
|
179
119
|
headers[key.toLowerCase()] = String(header);
|
|
180
120
|
}
|
|
181
121
|
}
|
|
182
122
|
if (!headers['content-length']) {
|
|
183
|
-
|
|
123
|
+
const contentLength = getContentLength(url);
|
|
184
124
|
if (Number.isFinite(contentLength)) {
|
|
185
125
|
headers['content-length'] = contentLength;
|
|
186
126
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.node.js","names":["_http","_interopRequireDefault","require","_https","_response","_headers","_decodeDataUri2","_fetchFile","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","isDataURL","url","startsWith","isRequestURL","fetchNode","_x","_x2","_fetchNode","_asyncToGenerator2","_regenerator","mark","_callee","options","_decodeDataUri","arrayBuffer","mimeType","response","syntheticResponseHeaders","originalUrl","body","headers","_getStatus","status","statusText","followRedirect","redirectUrl","wrap","_callee$","_context","prev","next","fetchFileNode","abrupt","sent","decodeDataUri","Response","endsWith","slice","createHTTPRequestReadStream","getHeaders","getStatus","undefined","has","generateRedirectUrl","get","t0","String","stop","_x3","_x4","_createHTTPRequestReadStream","_callee2","_callee2$","_context2","Promise","resolve","reject","requestOptions","getRequestOptions","req","https","request","res","http","on","error","end","location","URL","pathname","href","originalHeaders","_i","_Object$keys","toLowerCase","urlObject","hostname","path","method","fetch","port","httpResponse","statusCode","statusMessage","additionalHeaders","httpHeaders","header","contentLength","getContentLength","Number","isFinite","assign","Headers"],"sources":["../../../../src/node/fetch/fetch.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport http from 'http';\nimport https from 'https';\nimport {Response} from './response.node';\nimport {Headers} from './headers.node';\nimport {decodeDataUri} from './utils/decode-data-uri.node';\n\nimport {fetchFileNode} from './fetch-file.node';\n\nconst isDataURL = (url: string): boolean => url.startsWith('data:');\nconst isRequestURL = (url: string): boolean => url.startsWith('http:') || url.startsWith('https:');\n\n/**\n * Emulation of Browser fetch for Node.js\n * @param url\n * @param options\n */\n// eslint-disable-next-line complexity\nexport async function fetchNode(url: string, options): Promise<Response> {\n try {\n // Handle file streams in node\n if (!isRequestURL(url) && !isDataURL(url)) {\n return await fetchFileNode(url, options);\n }\n\n // Handle data urls in node, to match `fetch``\n // Note - this loses the MIME type, data URIs are handled directly in fetch\n if (isDataURL(url)) {\n const {arrayBuffer, mimeType} = decodeDataUri(url);\n const response = new Response(arrayBuffer, {\n headers: {'content-type': mimeType},\n url\n });\n return response;\n }\n\n // Automatically decompress gzipped files with .gz extension\n const syntheticResponseHeaders = {};\n const originalUrl = url;\n if (url.endsWith('.gz')) {\n url = url.slice(0, -3);\n syntheticResponseHeaders['content-encoding'] = 'gzip';\n }\n\n // Need to create the stream in advance since Response constructor needs to be sync\n const body = await createHTTPRequestReadStream(originalUrl, options);\n const headers = getHeaders(url, body, syntheticResponseHeaders);\n const {status, statusText} = getStatus(body);\n\n const followRedirect =\n !options || options.followRedirect || options.followRedirect === undefined;\n\n if (status >= 300 && status < 400 && headers.has('location') && followRedirect) {\n const redirectUrl = generateRedirectUrl(url, headers.get('location'));\n\n // Redirect\n return await fetchNode(redirectUrl, options);\n }\n return new Response(body, {headers, status, statusText, url});\n } catch (error) {\n // TODO - what error code to use here?\n return new Response(null, {status: 400, statusText: String(error), url});\n }\n}\n\n/** Returns a promise that resolves to a readable stream */\nexport async function createHTTPRequestReadStream(\n url: string,\n options\n): Promise<http.IncomingMessage> {\n // HANDLE HTTP/HTTPS REQUESTS IN NODE\n // TODO: THIS IS BAD SINCE WE RETURN A PROMISE INSTEAD OF A STREAM\n return await new Promise((resolve, reject) => {\n const requestOptions = getRequestOptions(url, options);\n const req = url.startsWith('https:')\n ? https.request(requestOptions, (res) => resolve(res))\n : http.request(requestOptions, (res) => resolve(res));\n req.on('error', (error) => reject(error));\n req.end();\n });\n}\n\n/**\n * Generate redirect url from location without origin and protocol.\n * @param originalUrl\n * @param redirectUrl\n */\nfunction generateRedirectUrl(originalUrl: string, location: string): string {\n if (location.startsWith('http')) {\n return location;\n }\n // If url doesn't have origin and protocol just extend current url origin with location.\n const url = new URL(originalUrl);\n url.pathname = location;\n\n return url.href;\n}\n\n// HELPER FUNCTIONS\n\nfunction getRequestOptions(url: string, options?: {fetch?: typeof fetch; headers?}) {\n // Ensure header keys are lower case so that we can merge without duplicates\n const originalHeaders = options?.headers || {};\n const headers = {};\n for (const key of Object.keys(originalHeaders)) {\n headers[key.toLowerCase()] = originalHeaders[key];\n }\n\n // Add default accept-encoding to headers\n headers['accept-encoding'] = headers['accept-encoding'] || 'gzip,br,deflate';\n\n const urlObject = new URL(url);\n return {\n hostname: urlObject.hostname,\n path: urlObject.pathname,\n method: 'GET',\n // Add options and user provided 'options.fetch' overrides if available\n ...options,\n ...options?.fetch,\n // Override with updated headers with accepted encodings:\n headers,\n port: urlObject.port\n };\n}\n\nfunction getStatus(httpResponse: http.IncomingMessage): {status: number; statusText: string} {\n if (httpResponse.statusCode) {\n return {status: httpResponse.statusCode, statusText: httpResponse.statusMessage || 'NA'};\n }\n return {status: 200, statusText: 'OK'};\n}\n\nfunction getHeaders(url, httpResponse, additionalHeaders = {}) {\n const headers = {};\n\n if (httpResponse && httpResponse.headers) {\n const httpHeaders = httpResponse.headers;\n for (const key in httpHeaders) {\n const header = httpHeaders[key];\n headers[key.toLowerCase()] = String(header);\n }\n }\n\n // Fix up content length if we can for best progress experience\n if (!headers['content-length']) {\n const contentLength = getContentLength(url);\n if (Number.isFinite(contentLength)) {\n headers['content-length'] = contentLength;\n }\n }\n\n Object.assign(headers, additionalHeaders);\n\n return new Headers(headers);\n}\n\n/** Needs to be read from actual headers */\nfunction getContentLength(url: string): number | null {\n // TODO - remove media type etc\n return isDataURL(url) ? url.length - 'data:'.length : null;\n}\n"],"mappings":";;;;;;;;;;;A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AAY,CAAC7D,OAAO,EAAE;IACxC,IAAMiE,WAAW,GAAGJ,YAAY,CAAC7D,OAAO;IACxC,KAAK,IAAM1B,GAAG,IAAI2F,WAAW,EAAE;MAC7B,IAAMC,MAAM,GAAGD,WAAW,CAAC3F,GAAG,CAAC;MAC/B0B,OAAO,CAAC1B,GAAG,CAACgF,WAAW,CAAC,CAAC,CAAC,GAAG5B,MAAM,CAACwC,MAAM,CAAC;IAC7C;EACF;EAGA,IAAI,CAAClE,OAAO,CAAC,gBAAgB,CAAC,EAAE;IAC9B,IAAMmE,aAAa,GAAGC,gBAAgB,CAACvF,GAAG,CAAC;IAC3C,IAAIwF,MAAM,CAACC,QAAQ,CAACH,aAAa,CAAC,EAAE;MAClCnE,OAAO,CAAC,gBAAgB,CAAC,GAAGmE,aAAa;IAC3C;EACF;EAEA7G,MAAM,CAACiH,MAAM,CAACvE,OAAO,EAAEgE,iBAAiB,CAAC;EAEzC,OAAO,IAAIQ,gBAAO,CAACxE,OAAO,CAAC;AAC7B;AAGA,SAASoE,gBAAgBA,CAACvF,GAAW,EAAiB;EAEpD,OAAOD,SAAS,CAACC,GAAG,CAAC,GAAGA,GAAG,CAACV,MAAM,GAAG,OAAO,CAACA,MAAM,GAAG,IAAI;AAC5D"}
|
|
1
|
+
{"version":3,"file":"fetch.node.js","names":["_http","_interopRequireDefault","require","_https","_response","_headers","_decodeDataUri","_fetchFile","isDataURL","url","startsWith","isRequestURL","fetchNode","options","fetchFileNode","arrayBuffer","mimeType","decodeDataUri","response","Response","headers","syntheticResponseHeaders","originalUrl","endsWith","slice","body","createHTTPRequestReadStream","getHeaders","status","statusText","getStatus","followRedirect","undefined","has","redirectUrl","generateRedirectUrl","get","error","String","Promise","resolve","reject","requestOptions","getRequestOptions","req","https","request","res","http","on","end","location","URL","pathname","href","originalHeaders","key","Object","keys","toLowerCase","urlObject","hostname","path","method","fetch","port","httpResponse","statusCode","statusMessage","additionalHeaders","arguments","length","httpHeaders","header","contentLength","getContentLength","Number","isFinite","assign","Headers"],"sources":["../../../../src/node/fetch/fetch.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport http from 'http';\nimport https from 'https';\nimport {Response} from './response.node';\nimport {Headers} from './headers.node';\nimport {decodeDataUri} from './utils/decode-data-uri.node';\n\nimport {fetchFileNode} from './fetch-file.node';\n\nconst isDataURL = (url: string): boolean => url.startsWith('data:');\nconst isRequestURL = (url: string): boolean => url.startsWith('http:') || url.startsWith('https:');\n\n/**\n * Emulation of Browser fetch for Node.js\n * @param url\n * @param options\n */\n// eslint-disable-next-line complexity\nexport async function fetchNode(url: string, options): Promise<Response> {\n try {\n // Handle file streams in node\n if (!isRequestURL(url) && !isDataURL(url)) {\n return await fetchFileNode(url, options);\n }\n\n // Handle data urls in node, to match `fetch``\n // Note - this loses the MIME type, data URIs are handled directly in fetch\n if (isDataURL(url)) {\n const {arrayBuffer, mimeType} = decodeDataUri(url);\n const response = new Response(arrayBuffer, {\n headers: {'content-type': mimeType},\n url\n });\n return response;\n }\n\n // Automatically decompress gzipped files with .gz extension\n const syntheticResponseHeaders = {};\n const originalUrl = url;\n if (url.endsWith('.gz')) {\n url = url.slice(0, -3);\n syntheticResponseHeaders['content-encoding'] = 'gzip';\n }\n\n // Need to create the stream in advance since Response constructor needs to be sync\n const body = await createHTTPRequestReadStream(originalUrl, options);\n const headers = getHeaders(url, body, syntheticResponseHeaders);\n const {status, statusText} = getStatus(body);\n\n const followRedirect =\n !options || options.followRedirect || options.followRedirect === undefined;\n\n if (status >= 300 && status < 400 && headers.has('location') && followRedirect) {\n const redirectUrl = generateRedirectUrl(url, headers.get('location'));\n\n // Redirect\n return await fetchNode(redirectUrl, options);\n }\n return new Response(body, {headers, status, statusText, url});\n } catch (error) {\n // TODO - what error code to use here?\n return new Response(null, {status: 400, statusText: String(error), url});\n }\n}\n\n/** Returns a promise that resolves to a readable stream */\nexport async function createHTTPRequestReadStream(\n url: string,\n options\n): Promise<http.IncomingMessage> {\n // HANDLE HTTP/HTTPS REQUESTS IN NODE\n // TODO: THIS IS BAD SINCE WE RETURN A PROMISE INSTEAD OF A STREAM\n return await new Promise((resolve, reject) => {\n const requestOptions = getRequestOptions(url, options);\n const req = url.startsWith('https:')\n ? https.request(requestOptions, (res) => resolve(res))\n : http.request(requestOptions, (res) => resolve(res));\n req.on('error', (error) => reject(error));\n req.end();\n });\n}\n\n/**\n * Generate redirect url from location without origin and protocol.\n * @param originalUrl\n * @param redirectUrl\n */\nfunction generateRedirectUrl(originalUrl: string, location: string): string {\n if (location.startsWith('http')) {\n return location;\n }\n // If url doesn't have origin and protocol just extend current url origin with location.\n const url = new URL(originalUrl);\n url.pathname = location;\n\n return url.href;\n}\n\n// HELPER FUNCTIONS\n\nfunction getRequestOptions(url: string, options?: {fetch?: typeof fetch; headers?}) {\n // Ensure header keys are lower case so that we can merge without duplicates\n const originalHeaders = options?.headers || {};\n const headers = {};\n for (const key of Object.keys(originalHeaders)) {\n headers[key.toLowerCase()] = originalHeaders[key];\n }\n\n // Add default accept-encoding to headers\n headers['accept-encoding'] = headers['accept-encoding'] || 'gzip,br,deflate';\n\n const urlObject = new URL(url);\n return {\n hostname: urlObject.hostname,\n path: urlObject.pathname,\n method: 'GET',\n // Add options and user provided 'options.fetch' overrides if available\n ...options,\n ...options?.fetch,\n // Override with updated headers with accepted encodings:\n headers,\n port: urlObject.port\n };\n}\n\nfunction getStatus(httpResponse: http.IncomingMessage): {status: number; statusText: string} {\n if (httpResponse.statusCode) {\n return {status: httpResponse.statusCode, statusText: httpResponse.statusMessage || 'NA'};\n }\n return {status: 200, statusText: 'OK'};\n}\n\nfunction getHeaders(url, httpResponse, additionalHeaders = {}) {\n const headers = {};\n\n if (httpResponse && httpResponse.headers) {\n const httpHeaders = httpResponse.headers;\n for (const key in httpHeaders) {\n const header = httpHeaders[key];\n headers[key.toLowerCase()] = String(header);\n }\n }\n\n // Fix up content length if we can for best progress experience\n if (!headers['content-length']) {\n const contentLength = getContentLength(url);\n if (Number.isFinite(contentLength)) {\n headers['content-length'] = contentLength;\n }\n }\n\n Object.assign(headers, additionalHeaders);\n\n return new Headers(headers);\n}\n\n/** Needs to be read from actual headers */\nfunction getContentLength(url: string): number | null {\n // TODO - remove media type etc\n return isDataURL(url) ? url.length - 'data:'.length : null;\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AAEA,IAAAK,UAAA,GAAAL,OAAA;AAEA,MAAMM,SAAS,GAAIC,GAAW,IAAcA,GAAG,CAACC,UAAU,CAAC,OAAO,CAAC;AACnE,MAAMC,YAAY,GAAIF,GAAW,IAAcA,GAAG,CAACC,UAAU,CAAC,OAAO,CAAC,IAAID,GAAG,CAACC,UAAU,CAAC,QAAQ,CAAC;AAQ3F,eAAeE,SAASA,CAACH,GAAW,EAAEI,OAAO,EAAqB;EACvE,IAAI;IAEF,IAAI,CAACF,YAAY,CAACF,GAAG,CAAC,IAAI,CAACD,SAAS,CAACC,GAAG,CAAC,EAAE;MACzC,OAAO,MAAM,IAAAK,wBAAa,EAACL,GAAG,EAAEI,OAAO,CAAC;IAC1C;IAIA,IAAIL,SAAS,CAACC,GAAG,CAAC,EAAE;MAClB,MAAM;QAACM,WAAW;QAAEC;MAAQ,CAAC,GAAG,IAAAC,4BAAa,EAACR,GAAG,CAAC;MAClD,MAAMS,QAAQ,GAAG,IAAIC,kBAAQ,CAACJ,WAAW,EAAE;QACzCK,OAAO,EAAE;UAAC,cAAc,EAAEJ;QAAQ,CAAC;QACnCP;MACF,CAAC,CAAC;MACF,OAAOS,QAAQ;IACjB;IAGA,MAAMG,wBAAwB,GAAG,CAAC,CAAC;IACnC,MAAMC,WAAW,GAAGb,GAAG;IACvB,IAAIA,GAAG,CAACc,QAAQ,CAAC,K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