Merge branch '459-activitypub-integration' of github.com:NuSkooler/enigma-bbs into 459-activitypub-integration

This commit is contained in:
Bryan Ashby 2023-02-12 17:48:42 -07:00
commit e90f42c53c
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
1 changed files with 14 additions and 1 deletions

View File

@ -1,10 +1,14 @@
const { Errors } = require('./enig_error.js'); const { Errors } = require('./enig_error.js');
// deps // deps
const { isString, isObject, truncate } = require('lodash'); const { isString, isObject, truncate, get, has } = require('lodash');
const https = require('https'); const https = require('https');
const httpSignature = require('http-signature'); const httpSignature = require('http-signature');
const crypto = require('crypto'); const crypto = require('crypto');
const Config = require('./config.js').get;
const TimeoutConfigPath = 'outbound.connectionTimeoutMilliseconds';
const DefaultTimeoutMilliseconds = 5000;
exports.getJson = getJson; exports.getJson = getJson;
exports.postJson = postJson; exports.postJson = postJson;
@ -56,6 +60,15 @@ function postJson(url, json, options, cb) {
} }
function _makeRequest(url, options, cb) { function _makeRequest(url, options, cb) {
let defaultTimeout = DefaultTimeoutMilliseconds;
// Only set to config value if it has one, this allows us to set it
// to zero, but still have a default if none is set
if (has(Config(), TimeoutConfigPath)) {
defaultTimeout = get(Config(), TimeoutConfigPath);
}
options = Object.assign({}, options, { timeout: defaultTimeout }); // Let options override default timeout if needed
if (options.body) { if (options.body) {
options.headers['Content-Length'] = Buffer.from(options.body).length; options.headers['Content-Length'] = Buffer.from(options.body).length;