From cf8202672c6d6fb7abfc4cc7a82eca74767d6e10 Mon Sep 17 00:00:00 2001 From: chrisradek Date: Wed, 2 Dec 2015 15:37:59 -0800 Subject: [PATCH] custom user agent now space delimited and can be provided as an array or a string --- lib/config.js | 5 ----- lib/http.js | 7 ++++++- test/http_request.spec.coffee | 10 ++++++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/config.js b/lib/config.js index e7292d2dc9..9e3848855b 100644 --- a/lib/config.js +++ b/lib/config.js @@ -54,9 +54,6 @@ require('./credentials/credential_provider_chain'); * requests that fail because of an skewed client clock. Defaults to * `false`. * - * @!attribute customUserAgent - * @return [String] a custom identifier to append to user agent headers. - * * @!attribute sslEnabled * @return [Boolean] whether SSL is enabled for requests * @@ -153,8 +150,6 @@ AWS.Config = AWS.util.inherit({ * @option options correctClockSkew [Boolean] whether to apply a clock skew * correction and retry requests that fail because of an skewed client * clock. Defaults to `false`. - * @option options customUserAgent [String] A custom identifier to append to - * user agent headers. * @option options s3ForcePathStyle [Boolean] whether to force path * style URLs for S3 objects. * @option options s3BucketEndpoint [Boolean] whether the provided endpoint diff --git a/lib/http.js b/lib/http.js index 5a20b96f7b..1991469882 100644 --- a/lib/http.js +++ b/lib/http.js @@ -108,7 +108,12 @@ AWS.HttpRequest = inherit({ */ setUserAgent: function setUserAgent(customUserAgent) { var prefix = AWS.util.isBrowser() ? 'X-Amz-' : ''; - var customSuffix = (typeof customUserAgent === 'string' && customUserAgent) ? '/' + customUserAgent : ''; + var customSuffix = ''; + if (Array.isArray(customUserAgent) && customUserAgent.length) { + customSuffix += ' ' + customUserAgent.join('/'); + } else if (typeof customUserAgent === 'string' && customUserAgent) { + customSuffix += ' ' + customUserAgent; + } this.headers[prefix + 'User-Agent'] = AWS.util.userAgent() + customSuffix; }, diff --git a/test/http_request.spec.coffee b/test/http_request.spec.coffee index bee9767377..456ab95345 100644 --- a/test/http_request.spec.coffee +++ b/test/http_request.spec.coffee @@ -25,12 +25,18 @@ describe 'AWS.HttpRequest', -> headers[agentHeader] = AWS.util.userAgent() expect(request.headers).to.eql(headers) - it 'adds the customUserAgent to the user agent header if provided', -> + it 'adds the customUserAgent to the user agent header if provided as string', -> headers = {} - headers[agentHeader] = AWS.util.userAgent() + '/custom' + headers[agentHeader] = AWS.util.userAgent() + ' custom' request = new AWS.HttpRequest('http://domain.com', '', 'custom') expect(request.headers).to.eql(headers) + it 'adds the customUserAgent to the user agent header if provided as array', -> + headers = {} + headers[agentHeader] = AWS.util.userAgent() + ' custom/1' + request = new AWS.HttpRequest('http://domain.com', '', ['custom', 1]) + expect(request.headers).to.eql(headers) + it 'defaults body to empty string', -> expect(request.body).to.equal('')