From 2e216182906354808f427379bf45410c070f0591 Mon Sep 17 00:00:00 2001 From: Tim Birkett Date: Mon, 28 Jan 2019 16:01:34 +0000 Subject: [PATCH] Set Ghost user-agent header for got requests (#10424) no-issue Currently the `user-agent` header is the for outgoing webhook calls is the `got` default: `User-Agent: got/8.3.2 (https://github.com/sindresorhus/got)`. This is pretty unfriendly to the receiver of the webhook who may wish to perform analytics on calling systems, implement security features based on calling system or take action based on different versions of a client. This PR sets the header to: `User-Agent: Ghost/2.12.0 (https://github.com/TryGhost/Ghost)` which is much more descriptive. --- core/server/lib/request.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/server/lib/request.js b/core/server/lib/request.js index 8dfab554b6..d58fdcdcdc 100644 --- a/core/server/lib/request.js +++ b/core/server/lib/request.js @@ -1,7 +1,14 @@ var got = require('got'), _ = require('lodash'), validator = require('../data/validation').validator, - common = require('./common'); + common = require('./common'), + ghostVersion = require('./ghost-version'); + +var defaultOptions = { + headers: { + 'user-agent': 'Ghost/' + ghostVersion.original + ' (https://github.com/TryGhost/Ghost)' + } +}; module.exports = function request(url, options) { if (_.isEmpty(url) || !validator.isURL(url)) { @@ -12,5 +19,7 @@ module.exports = function request(url, options) { })); } - return got(url, options); + var mergedOptions = _.merge({}, defaultOptions, options); + + return got(url, mergedOptions); };