You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by gl...@apache.org on 2020/02/27 16:10:03 UTC
[couchdb-nano] 09/12: configure default http agent,
user-agent string and gzipping
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 132a70bd5d22522f83c13a3318e6322c7d42b8de
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Fri Feb 14 08:10:25 2020 +0000
configure default http agent, user-agent string and gzipping
---
lib/nano.js | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/lib/nano.js b/lib/nano.js
index ee76018..254aeee 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -19,6 +19,10 @@ const follow = require('cloudant-follow')
const logger = require('./logger')
const INVALID_PARAMETERS_ERROR = new Error('Invalid parameters')
const stream = require('stream')
+const http = require('http')
+const https = require('https')
+const pkg = require('../package.json')
+const AGENT_DEFAULTS = { keepAlive: true, maxSockets: 50, keepAliveMsecs: 30000 }
function isEmpty (val) {
return val == null || !(Object.keys(val) || val).length
@@ -199,7 +203,9 @@ module.exports = exports = function dbScope (cfg) {
const headers = {
'content-type': 'application/json',
- accept: 'application/json'
+ accept: 'application/json',
+ 'user-agent': `${pkg.name}/${pkg.version} (Node.js ${process.version})`,
+ 'Accept-Encoding': 'deflate, gzip'
}
const req = Object.assign({
@@ -321,6 +327,8 @@ module.exports = exports = function dbScope (cfg) {
} else if (opts.dontParse) {
req.responseType = 'arraybuffer'
}
+ req.httpAgent = cfg.requestDefaults.agent || new http.Agent(AGENT_DEFAULTS)
+ req.httpsAgent = cfg.requestDefaults.agent || new https.Agent(AGENT_DEFAULTS)
// actually do the HTTP request
if (opts.stream) {