Skip to content

Commit

Permalink
custom user agent now space delimited and can be provided as an array…
Browse files Browse the repository at this point in the history
… or a string
  • Loading branch information
chrisradek committed Dec 2, 2015
1 parent 19a0e75 commit cf82026
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 0 additions & 5 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

Expand Down
10 changes: 8 additions & 2 deletions test/http_request.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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('')

Expand Down

0 comments on commit cf82026

Please sign in to comment.