This commit is contained in:
Dave Horton
2020-02-19 11:15:24 -05:00
parent 162dfff5a3
commit 802cc1944f
11 changed files with 1013 additions and 917 deletions

View File

@@ -31,15 +31,22 @@ class Requestor {
const u = parseUrl(this.url);
const myPort = u.port ? `:${u.port}` : '';
const baseUrl = `${u.protocol}://${u.resource}${myPort}`;
const baseUrl = this._baseUrl = `${u.protocol}://${u.resource}${myPort}`;
this.get = bent(baseUrl, 'GET', 'buffer', 200, 201);
this.post = bent(baseUrl, 'POST', 'buffer', 200, 201);
this.username = hook.username;
this.password = hook.password;
assert(isAbsoluteUrl(this.url));
assert(['GET', 'POST'].includes(this.method));
}
get baseUrl() {
return this._baseUrl;
}
/**
* Make an HTTP request.
* All requests use json bodies.
@@ -61,11 +68,11 @@ class Requestor {
assert.ok, (['GET', 'POST'].includes(method), `Requestor:request method must be 'GET' or 'POST' not ${method}`);
this.logger.debug({hook}, `Requestor:request ${method} ${url}`);
this.logger.debug({hook, params}, `Requestor:request ${method} ${url}`);
const buf = isRelativeUrl(url) ?
await this.post(url, params, this.authHeader) :
await bent(method, 'buffer', 200, 201)(url, params, basicAuth(username, password));
//this.logger.debug({body: }, `Requestor:request ${method} ${url} succeeded`);
this.logger.debug(`Requestor:request ${method} ${url} succeeded`);
if (buf && buf.toString().length > 0) {
try {