Skip to content

Commit

Permalink
Close #171 PR: Fix user-agent string RFC 2616 Section 14.43. Fixes #169
Browse files Browse the repository at this point in the history
  • Loading branch information
bem-robot authored and floatdrop committed Feb 16, 2016
1 parent f81e4eb commit b70e40b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var nodeStatusCodes = require('node-status-codes');
var isPlainObj = require('is-plain-obj');
var parseJson = require('parse-json');
var isRetryAllowed = require('is-retry-allowed');
var pkg = require('./package.json');

function requestAsEventEmitter(opts) {
opts = opts || {};
Expand Down Expand Up @@ -220,7 +221,7 @@ function normalizeArguments(url, opts) {
);

opts.headers = objectAssign({
'user-agent': 'https://github.com/sindresorhus/got',
'user-agent': pkg.name + '/' + pkg.version + ' (https://github.com/sindresorhus/got)',
'accept-encoding': 'gzip,deflate'
}, lowercaseKeys(opts.headers));

Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,11 @@ It's a good idea to set the `'user-agent'` header so the provider can more easil

```js
var got = require('got');
var pkg = require('./package.json');

got('todomvc.com', {
headers: {
'user-agent': 'https://github.com/your-username/repo-name'
'user-agent': 'my-module/' + pkg.version + ' (https://github.com/username/my-module)'
}
}, function () {});
```
Expand Down
3 changes: 2 additions & 1 deletion test/headers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import test from 'ava';
import got from '../';
import pkg from '../package.json';
import {createServer} from './_server';

let s;
Expand All @@ -17,7 +18,7 @@ test.before('setup', async t => {

test('user-agent', async t => {
const headers = (await got(s.url, {json: true})).body;
t.is(headers['user-agent'], 'https://github.com/sindresorhus/got');
t.is(headers['user-agent'], `${pkg.name}/${pkg.version} (https://github.com/sindresorhus/got)`);
});

test('accept-encoding', async t => {
Expand Down

0 comments on commit b70e40b

Please sign in to comment.