@opensearch-project/opensearch 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +2 -0
- package/.eslintrc.json +26 -0
- package/.prettierrc.json +5 -0
- package/.whitesource +15 -0
- package/ADMINS.md +18 -11
- package/COMPATIBILITY.md +24 -0
- package/DEVELOPER_GUIDE.md +22 -5
- package/MAINTAINERS.md +23 -18
- package/README.md +100 -101
- package/RELEASING.md +3 -3
- package/SECURITY.md +1 -1
- package/api/api/bulk.js +53 -26
- package/api/api/cat.js +354 -264
- package/api/api/clear_scroll.js +17 -17
- package/api/api/cluster.js +366 -219
- package/api/api/count.js +55 -24
- package/api/api/create.js +50 -24
- package/api/api/dangling_indices.js +95 -51
- package/api/api/delete.js +49 -22
- package/api/api/delete_by_query.js +88 -25
- package/api/api/delete_by_query_rethrottle.js +33 -19
- package/api/api/delete_script.js +31 -17
- package/api/api/exists.js +55 -22
- package/api/api/exists_source.js +60 -27
- package/api/api/explain.js +60 -22
- package/api/api/features.js +56 -35
- package/api/api/field_caps.js +36 -18
- package/api/api/get.js +55 -22
- package/api/api/get_script.js +30 -17
- package/api/api/get_script_context.js +15 -15
- package/api/api/get_script_languages.js +15 -15
- package/api/api/get_source.js +55 -22
- package/api/api/index.js +60 -28
- package/api/api/indices.js +1068 -857
- package/api/api/info.js +15 -15
- package/api/api/ingest.js +132 -96
- package/api/api/mget.js +50 -26
- package/api/api/msearch.js +49 -26
- package/api/api/msearch_template.js +53 -26
- package/api/api/mtermvectors.js +48 -24
- package/api/api/nodes.js +281 -154
- package/api/api/ping.js +15 -15
- package/api/api/put_script.js +40 -25
- package/api/api/rank_eval.js +37 -20
- package/api/api/reindex.js +38 -17
- package/api/api/reindex_rethrottle.js +32 -19
- package/api/api/render_search_template.js +18 -18
- package/api/api/scripts_painless_execute.js +15 -15
- package/api/api/scroll.js +31 -17
- package/api/api/search.js +108 -24
- package/api/api/search_shards.js +36 -18
- package/api/api/search_template.js +64 -26
- package/api/api/shutdown.js +66 -54
- package/api/api/snapshot.js +347 -224
- package/api/api/tasks.js +65 -46
- package/api/api/terms_enum.js +17 -17
- package/api/api/termvectors.js +57 -26
- package/api/api/update.js +64 -24
- package/api/api/update_by_query.js +89 -23
- package/api/api/update_by_query_rethrottle.js +33 -19
- package/api/index.js +267 -179
- package/api/new.d.ts +2042 -529
- package/api/opensearch_dashboards.d.ts +239 -236
- package/api/requestParams.d.ts +301 -69
- package/api/types.d.ts +6204 -5719
- package/api/utils.js +22 -22
- package/codecov.yml +2 -2
- package/index.d.ts +4776 -935
- package/index.js +152 -140
- package/index.mjs +9 -9
- package/lib/Connection.d.ts +37 -26
- package/lib/Connection.js +163 -168
- package/lib/Helpers.d.ts +103 -64
- package/lib/Helpers.js +398 -371
- package/lib/Serializer.d.ts +2 -2
- package/lib/Serializer.js +39 -39
- package/lib/Transport.d.ts +30 -12
- package/lib/Transport.js +375 -336
- package/lib/errors.d.ts +25 -7
- package/lib/errors.js +75 -71
- package/lib/pool/BaseConnectionPool.js +100 -97
- package/lib/pool/CloudConnectionPool.js +16 -16
- package/lib/pool/ConnectionPool.js +105 -105
- package/lib/pool/index.d.ts +8 -6
- package/lib/pool/index.js +6 -6
- package/package.json +13 -8
package/lib/Connection.js
CHANGED
|
@@ -28,189 +28,188 @@
|
|
|
28
28
|
* under the License.
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
'use strict'
|
|
32
|
-
|
|
33
|
-
const assert = require('assert')
|
|
34
|
-
const { inspect } = require('util')
|
|
35
|
-
const hpagent = require('hpagent')
|
|
36
|
-
const http = require('http')
|
|
37
|
-
const https = require('https')
|
|
38
|
-
const debug = require('debug')('opensearch')
|
|
39
|
-
const { pipeline } = require('stream')
|
|
40
|
-
const INVALID_PATH_REGEX = /[^\u0021-\u00ff]
|
|
31
|
+
'use strict';
|
|
32
|
+
|
|
33
|
+
const assert = require('assert');
|
|
34
|
+
const { inspect } = require('util');
|
|
35
|
+
const hpagent = require('hpagent');
|
|
36
|
+
const http = require('http');
|
|
37
|
+
const https = require('https');
|
|
38
|
+
const debug = require('debug')('opensearch');
|
|
39
|
+
const { pipeline } = require('stream');
|
|
40
|
+
const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/;
|
|
41
41
|
const {
|
|
42
42
|
ConnectionError,
|
|
43
43
|
RequestAbortedError,
|
|
44
44
|
TimeoutError,
|
|
45
|
-
ConfigurationError
|
|
46
|
-
} = require('./errors')
|
|
45
|
+
ConfigurationError,
|
|
46
|
+
} = require('./errors');
|
|
47
47
|
|
|
48
48
|
class Connection {
|
|
49
|
-
constructor
|
|
50
|
-
this.url = opts.url
|
|
51
|
-
this.ssl = opts.ssl || null
|
|
52
|
-
this.id = opts.id || stripAuth(opts.url.href)
|
|
53
|
-
this.headers = prepareHeaders(opts.headers, opts.auth)
|
|
54
|
-
this.deadCount = 0
|
|
55
|
-
this.resurrectTimeout = 0
|
|
56
|
-
|
|
57
|
-
this._openRequests = 0
|
|
58
|
-
this._status = opts.status || Connection.statuses.ALIVE
|
|
59
|
-
this.roles = Object.assign({}, defaultRoles, opts.roles)
|
|
49
|
+
constructor(opts) {
|
|
50
|
+
this.url = opts.url;
|
|
51
|
+
this.ssl = opts.ssl || null;
|
|
52
|
+
this.id = opts.id || stripAuth(opts.url.href);
|
|
53
|
+
this.headers = prepareHeaders(opts.headers, opts.auth);
|
|
54
|
+
this.deadCount = 0;
|
|
55
|
+
this.resurrectTimeout = 0;
|
|
56
|
+
|
|
57
|
+
this._openRequests = 0;
|
|
58
|
+
this._status = opts.status || Connection.statuses.ALIVE;
|
|
59
|
+
this.roles = Object.assign({}, defaultRoles, opts.roles);
|
|
60
60
|
|
|
61
61
|
if (!['http:', 'https:'].includes(this.url.protocol)) {
|
|
62
|
-
throw new ConfigurationError(`Invalid protocol: '${this.url.protocol}'`)
|
|
62
|
+
throw new ConfigurationError(`Invalid protocol: '${this.url.protocol}'`);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
if (typeof opts.agent === 'function') {
|
|
66
|
-
this.agent = opts.agent(opts)
|
|
66
|
+
this.agent = opts.agent(opts);
|
|
67
67
|
} else if (opts.agent === false) {
|
|
68
|
-
this.agent = undefined
|
|
68
|
+
this.agent = undefined;
|
|
69
69
|
} else {
|
|
70
|
-
const agentOptions = Object.assign(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
const agentOptions = Object.assign(
|
|
71
|
+
{},
|
|
72
|
+
{
|
|
73
|
+
keepAlive: true,
|
|
74
|
+
keepAliveMsecs: 1000,
|
|
75
|
+
maxSockets: 256,
|
|
76
|
+
maxFreeSockets: 256,
|
|
77
|
+
scheduling: 'lifo',
|
|
78
|
+
},
|
|
79
|
+
opts.agent
|
|
80
|
+
);
|
|
77
81
|
if (opts.proxy) {
|
|
78
|
-
agentOptions.proxy = opts.proxy
|
|
79
|
-
this.agent =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
agentOptions.proxy = opts.proxy;
|
|
83
|
+
this.agent =
|
|
84
|
+
this.url.protocol === 'http:'
|
|
85
|
+
? new hpagent.HttpProxyAgent(agentOptions)
|
|
86
|
+
: new hpagent.HttpsProxyAgent(Object.assign({}, agentOptions, this.ssl));
|
|
82
87
|
} else {
|
|
83
|
-
this.agent =
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
this.agent =
|
|
89
|
+
this.url.protocol === 'http:'
|
|
90
|
+
? new http.Agent(agentOptions)
|
|
91
|
+
: new https.Agent(Object.assign({}, agentOptions, this.ssl));
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
|
|
89
|
-
this.makeRequest = this.url.protocol === 'http:'
|
|
90
|
-
? http.request
|
|
91
|
-
: https.request
|
|
95
|
+
this.makeRequest = this.url.protocol === 'http:' ? http.request : https.request;
|
|
92
96
|
}
|
|
93
97
|
|
|
94
|
-
request
|
|
95
|
-
this._openRequests
|
|
96
|
-
let cleanedListeners = false
|
|
98
|
+
request(params, callback) {
|
|
99
|
+
this._openRequests++;
|
|
100
|
+
let cleanedListeners = false;
|
|
97
101
|
|
|
98
|
-
const requestParams = this.buildRequestObject(params)
|
|
102
|
+
const requestParams = this.buildRequestObject(params);
|
|
99
103
|
// https://github.com/nodejs/node/commit/b961d9fd83
|
|
100
104
|
if (INVALID_PATH_REGEX.test(requestParams.path) === true) {
|
|
101
|
-
callback(new TypeError(`ERR_UNESCAPED_CHARACTERS: ${requestParams.path}`), null)
|
|
105
|
+
callback(new TypeError(`ERR_UNESCAPED_CHARACTERS: ${requestParams.path}`), null);
|
|
102
106
|
/* istanbul ignore next */
|
|
103
|
-
return { abort: () => {
|
|
107
|
+
return { abort: () => {} };
|
|
104
108
|
}
|
|
105
109
|
|
|
106
|
-
debug('Starting a new request', params)
|
|
107
|
-
const request = this.makeRequest(requestParams)
|
|
110
|
+
debug('Starting a new request', params);
|
|
111
|
+
const request = this.makeRequest(requestParams);
|
|
108
112
|
|
|
109
|
-
const onResponse = response => {
|
|
110
|
-
cleanListeners()
|
|
111
|
-
this._openRequests
|
|
112
|
-
callback(null, response)
|
|
113
|
-
}
|
|
113
|
+
const onResponse = (response) => {
|
|
114
|
+
cleanListeners();
|
|
115
|
+
this._openRequests--;
|
|
116
|
+
callback(null, response);
|
|
117
|
+
};
|
|
114
118
|
|
|
115
119
|
const onTimeout = () => {
|
|
116
|
-
cleanListeners()
|
|
117
|
-
this._openRequests
|
|
118
|
-
request.once('error', () => {
|
|
119
|
-
request.abort()
|
|
120
|
-
callback(new TimeoutError('Request timed out', params), null)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const onError = err => {
|
|
124
|
-
cleanListeners()
|
|
125
|
-
this._openRequests
|
|
126
|
-
callback(new ConnectionError(err.message), null)
|
|
127
|
-
}
|
|
120
|
+
cleanListeners();
|
|
121
|
+
this._openRequests--;
|
|
122
|
+
request.once('error', () => {}); // we need to catch the request aborted error
|
|
123
|
+
request.abort();
|
|
124
|
+
callback(new TimeoutError('Request timed out', params), null);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const onError = (err) => {
|
|
128
|
+
cleanListeners();
|
|
129
|
+
this._openRequests--;
|
|
130
|
+
callback(new ConnectionError(err.message), null);
|
|
131
|
+
};
|
|
128
132
|
|
|
129
133
|
const onAbort = () => {
|
|
130
|
-
cleanListeners()
|
|
131
|
-
request.once('error', () => {
|
|
132
|
-
debug('Request aborted', params)
|
|
133
|
-
this._openRequests
|
|
134
|
-
callback(new RequestAbortedError(), null)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
request.on('response', onResponse)
|
|
138
|
-
request.on('timeout', onTimeout)
|
|
139
|
-
request.on('error', onError)
|
|
140
|
-
request.on('abort', onAbort)
|
|
134
|
+
cleanListeners();
|
|
135
|
+
request.once('error', () => {}); // we need to catch the request aborted error
|
|
136
|
+
debug('Request aborted', params);
|
|
137
|
+
this._openRequests--;
|
|
138
|
+
callback(new RequestAbortedError(), null);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
request.on('response', onResponse);
|
|
142
|
+
request.on('timeout', onTimeout);
|
|
143
|
+
request.on('error', onError);
|
|
144
|
+
request.on('abort', onAbort);
|
|
141
145
|
|
|
142
146
|
// Disables the Nagle algorithm
|
|
143
|
-
request.setNoDelay(true)
|
|
147
|
+
request.setNoDelay(true);
|
|
144
148
|
|
|
145
149
|
// starts the request
|
|
146
150
|
if (isStream(params.body) === true) {
|
|
147
|
-
pipeline(params.body, request, err => {
|
|
151
|
+
pipeline(params.body, request, (err) => {
|
|
148
152
|
/* istanbul ignore if */
|
|
149
153
|
if (err != null && cleanedListeners === false) {
|
|
150
|
-
cleanListeners()
|
|
151
|
-
this._openRequests
|
|
152
|
-
callback(err, null)
|
|
154
|
+
cleanListeners();
|
|
155
|
+
this._openRequests--;
|
|
156
|
+
callback(err, null);
|
|
153
157
|
}
|
|
154
|
-
})
|
|
158
|
+
});
|
|
155
159
|
} else {
|
|
156
|
-
request.end(params.body)
|
|
160
|
+
request.end(params.body);
|
|
157
161
|
}
|
|
158
162
|
|
|
159
|
-
return request
|
|
163
|
+
return request;
|
|
160
164
|
|
|
161
|
-
function cleanListeners
|
|
162
|
-
request.removeListener('response', onResponse)
|
|
163
|
-
request.removeListener('timeout', onTimeout)
|
|
164
|
-
request.removeListener('error', onError)
|
|
165
|
-
request.removeListener('abort', onAbort)
|
|
166
|
-
cleanedListeners = true
|
|
165
|
+
function cleanListeners() {
|
|
166
|
+
request.removeListener('response', onResponse);
|
|
167
|
+
request.removeListener('timeout', onTimeout);
|
|
168
|
+
request.removeListener('error', onError);
|
|
169
|
+
request.removeListener('abort', onAbort);
|
|
170
|
+
cleanedListeners = true;
|
|
167
171
|
}
|
|
168
172
|
}
|
|
169
173
|
|
|
170
174
|
// TODO: write a better closing logic
|
|
171
|
-
close
|
|
172
|
-
debug('Closing connection', this.id)
|
|
175
|
+
close(callback = () => {}) {
|
|
176
|
+
debug('Closing connection', this.id);
|
|
173
177
|
if (this._openRequests > 0) {
|
|
174
|
-
setTimeout(() => this.close(callback), 1000)
|
|
178
|
+
setTimeout(() => this.close(callback), 1000);
|
|
175
179
|
} else {
|
|
176
180
|
if (this.agent !== undefined) {
|
|
177
|
-
this.agent.destroy()
|
|
181
|
+
this.agent.destroy();
|
|
178
182
|
}
|
|
179
|
-
callback()
|
|
183
|
+
callback();
|
|
180
184
|
}
|
|
181
185
|
}
|
|
182
186
|
|
|
183
|
-
setRole
|
|
187
|
+
setRole(role, enabled) {
|
|
184
188
|
if (validRoles.indexOf(role) === -1) {
|
|
185
|
-
throw new ConfigurationError(`Unsupported role: '${role}'`)
|
|
189
|
+
throw new ConfigurationError(`Unsupported role: '${role}'`);
|
|
186
190
|
}
|
|
187
191
|
if (typeof enabled !== 'boolean') {
|
|
188
|
-
throw new ConfigurationError('enabled should be a boolean')
|
|
192
|
+
throw new ConfigurationError('enabled should be a boolean');
|
|
189
193
|
}
|
|
190
194
|
|
|
191
|
-
this.roles[role] = enabled
|
|
192
|
-
return this
|
|
195
|
+
this.roles[role] = enabled;
|
|
196
|
+
return this;
|
|
193
197
|
}
|
|
194
198
|
|
|
195
|
-
get status
|
|
196
|
-
return this._status
|
|
199
|
+
get status() {
|
|
200
|
+
return this._status;
|
|
197
201
|
}
|
|
198
202
|
|
|
199
|
-
set status
|
|
200
|
-
assert(
|
|
201
|
-
|
|
202
|
-
`Unsupported status: '${status}'`
|
|
203
|
-
)
|
|
204
|
-
this._status = status
|
|
203
|
+
set status(status) {
|
|
204
|
+
assert(~validStatuses.indexOf(status), `Unsupported status: '${status}'`);
|
|
205
|
+
this._status = status;
|
|
205
206
|
}
|
|
206
207
|
|
|
207
|
-
buildRequestObject
|
|
208
|
-
const url = this.url
|
|
208
|
+
buildRequestObject(params) {
|
|
209
|
+
const url = this.url;
|
|
209
210
|
const request = {
|
|
210
211
|
protocol: url.protocol,
|
|
211
|
-
hostname: url.hostname[0] === '['
|
|
212
|
-
? url.hostname.slice(1, -1)
|
|
213
|
-
: url.hostname,
|
|
212
|
+
hostname: url.hostname[0] === '[' ? url.hostname.slice(1, -1) : url.hostname,
|
|
214
213
|
hash: url.hash,
|
|
215
214
|
search: url.search,
|
|
216
215
|
pathname: url.pathname,
|
|
@@ -220,41 +219,38 @@ class Connection {
|
|
|
220
219
|
// https://github.com/elastic/elasticsearch-js/issues/843
|
|
221
220
|
port: url.port !== '' ? url.port : undefined,
|
|
222
221
|
headers: this.headers,
|
|
223
|
-
agent: this.agent
|
|
224
|
-
}
|
|
222
|
+
agent: this.agent,
|
|
223
|
+
};
|
|
225
224
|
|
|
226
|
-
const paramsKeys = Object.keys(params)
|
|
225
|
+
const paramsKeys = Object.keys(params);
|
|
227
226
|
for (let i = 0, len = paramsKeys.length; i < len; i++) {
|
|
228
|
-
const key = paramsKeys[i]
|
|
227
|
+
const key = paramsKeys[i];
|
|
229
228
|
if (key === 'path') {
|
|
230
|
-
request.pathname = resolve(request.pathname, params[key])
|
|
229
|
+
request.pathname = resolve(request.pathname, params[key]);
|
|
231
230
|
} else if (key === 'querystring' && !!params[key] === true) {
|
|
232
231
|
if (request.search === '') {
|
|
233
|
-
request.search = '?' + params[key]
|
|
232
|
+
request.search = '?' + params[key];
|
|
234
233
|
} else {
|
|
235
|
-
request.search += '&' + params[key]
|
|
234
|
+
request.search += '&' + params[key];
|
|
236
235
|
}
|
|
237
236
|
} else if (key === 'headers') {
|
|
238
|
-
request.headers = Object.assign({}, request.headers, params.headers)
|
|
237
|
+
request.headers = Object.assign({}, request.headers, params.headers);
|
|
239
238
|
} else {
|
|
240
|
-
request[key] = params[key]
|
|
239
|
+
request[key] = params[key];
|
|
241
240
|
}
|
|
242
241
|
}
|
|
243
242
|
|
|
244
|
-
request.path = request.pathname + request.search
|
|
243
|
+
request.path = request.pathname + request.search;
|
|
245
244
|
|
|
246
|
-
return request
|
|
245
|
+
return request;
|
|
247
246
|
}
|
|
248
247
|
|
|
249
248
|
// Handles console.log and utils.inspect invocations.
|
|
250
249
|
// We want to hide `auth`, `agent` and `ssl` since they made
|
|
251
250
|
// the logs very hard to read. The user can still
|
|
252
251
|
// access them with `instance.agent` and `instance.ssl`.
|
|
253
|
-
[inspect.custom]
|
|
254
|
-
const {
|
|
255
|
-
authorization,
|
|
256
|
-
...headers
|
|
257
|
-
} = this.headers
|
|
252
|
+
[inspect.custom](depth, options) {
|
|
253
|
+
const { authorization, ...headers } = this.headers;
|
|
258
254
|
|
|
259
255
|
return {
|
|
260
256
|
url: stripAuth(this.url.toString()),
|
|
@@ -264,15 +260,12 @@ class Connection {
|
|
|
264
260
|
resurrectTimeout: this.resurrectTimeout,
|
|
265
261
|
_openRequests: this._openRequests,
|
|
266
262
|
status: this.status,
|
|
267
|
-
roles: this.roles
|
|
268
|
-
}
|
|
263
|
+
roles: this.roles,
|
|
264
|
+
};
|
|
269
265
|
}
|
|
270
266
|
|
|
271
|
-
toJSON
|
|
272
|
-
const {
|
|
273
|
-
authorization,
|
|
274
|
-
...headers
|
|
275
|
-
} = this.headers
|
|
267
|
+
toJSON() {
|
|
268
|
+
const { authorization, ...headers } = this.headers;
|
|
276
269
|
|
|
277
270
|
return {
|
|
278
271
|
url: stripAuth(this.url.toString()),
|
|
@@ -282,64 +275,66 @@ class Connection {
|
|
|
282
275
|
resurrectTimeout: this.resurrectTimeout,
|
|
283
276
|
_openRequests: this._openRequests,
|
|
284
277
|
status: this.status,
|
|
285
|
-
roles: this.roles
|
|
286
|
-
}
|
|
278
|
+
roles: this.roles,
|
|
279
|
+
};
|
|
287
280
|
}
|
|
288
281
|
}
|
|
289
282
|
|
|
290
283
|
Connection.statuses = {
|
|
291
284
|
ALIVE: 'alive',
|
|
292
|
-
DEAD: 'dead'
|
|
293
|
-
}
|
|
285
|
+
DEAD: 'dead',
|
|
286
|
+
};
|
|
294
287
|
|
|
295
288
|
Connection.roles = {
|
|
289
|
+
CLUSTER_MANAGER: 'cluster_manager',
|
|
290
|
+
/**
|
|
291
|
+
* @deprecated use CLUSTER_MANAGER instead
|
|
292
|
+
*/
|
|
296
293
|
MASTER: 'master',
|
|
297
294
|
DATA: 'data',
|
|
298
|
-
INGEST: 'ingest'
|
|
299
|
-
}
|
|
295
|
+
INGEST: 'ingest',
|
|
296
|
+
};
|
|
300
297
|
|
|
301
298
|
const defaultRoles = {
|
|
302
|
-
[Connection.roles.MASTER]: true,
|
|
303
299
|
[Connection.roles.DATA]: true,
|
|
304
|
-
[Connection.roles.INGEST]: true
|
|
305
|
-
}
|
|
300
|
+
[Connection.roles.INGEST]: true,
|
|
301
|
+
};
|
|
306
302
|
|
|
307
|
-
const validStatuses = Object.keys(Connection.statuses)
|
|
308
|
-
|
|
309
|
-
const validRoles = Object.keys(Connection.roles)
|
|
310
|
-
.map(k => Connection.roles[k])
|
|
303
|
+
const validStatuses = Object.keys(Connection.statuses).map((k) => Connection.statuses[k]);
|
|
304
|
+
const validRoles = Object.keys(Connection.roles).map((k) => Connection.roles[k]);
|
|
311
305
|
|
|
312
|
-
function stripAuth
|
|
313
|
-
if (url.indexOf('@') === -1) return url
|
|
314
|
-
return url.slice(0, url.indexOf('//') + 2) + url.slice(url.indexOf('@') + 1)
|
|
306
|
+
function stripAuth(url) {
|
|
307
|
+
if (url.indexOf('@') === -1) return url;
|
|
308
|
+
return url.slice(0, url.indexOf('//') + 2) + url.slice(url.indexOf('@') + 1);
|
|
315
309
|
}
|
|
316
310
|
|
|
317
|
-
function isStream
|
|
318
|
-
return obj != null && typeof obj.pipe === 'function'
|
|
311
|
+
function isStream(obj) {
|
|
312
|
+
return obj != null && typeof obj.pipe === 'function';
|
|
319
313
|
}
|
|
320
314
|
|
|
321
|
-
function resolve
|
|
322
|
-
const hostEndWithSlash = host[host.length - 1] === '/'
|
|
323
|
-
const pathStartsWithSlash = path[0] === '/'
|
|
315
|
+
function resolve(host, path) {
|
|
316
|
+
const hostEndWithSlash = host[host.length - 1] === '/';
|
|
317
|
+
const pathStartsWithSlash = path[0] === '/';
|
|
324
318
|
|
|
325
319
|
if (hostEndWithSlash === true && pathStartsWithSlash === true) {
|
|
326
|
-
return host + path.slice(1)
|
|
320
|
+
return host + path.slice(1);
|
|
327
321
|
} else if (hostEndWithSlash !== pathStartsWithSlash) {
|
|
328
|
-
return host + path
|
|
322
|
+
return host + path;
|
|
329
323
|
} else {
|
|
330
|
-
return host + '/' + path
|
|
324
|
+
return host + '/' + path;
|
|
331
325
|
}
|
|
332
326
|
}
|
|
333
327
|
|
|
334
|
-
function prepareHeaders
|
|
328
|
+
function prepareHeaders(headers = {}, auth) {
|
|
335
329
|
if (auth != null && headers.authorization == null) {
|
|
336
330
|
/* istanbul ignore else */
|
|
337
331
|
if (auth.username && auth.password) {
|
|
338
|
-
headers.authorization =
|
|
332
|
+
headers.authorization =
|
|
333
|
+
'Basic ' + Buffer.from(`${auth.username}:${auth.password}`).toString('base64');
|
|
339
334
|
}
|
|
340
335
|
}
|
|
341
|
-
return headers
|
|
336
|
+
return headers;
|
|
342
337
|
}
|
|
343
338
|
|
|
344
|
-
module.exports = Connection
|
|
345
|
-
module.exports.internals = { prepareHeaders }
|
|
339
|
+
module.exports = Connection;
|
|
340
|
+
module.exports.internals = { prepareHeaders };
|