-
-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow specifying the user-agent header for outgoing requests (#1287
) Co-authored-by: Filip Skokan <[email protected]>
- Loading branch information
1 parent
503f313
commit c77513c
Showing
3 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import merge from 'lodash/merge.js'; | ||
|
||
import getConfig from '../../default.config.js'; | ||
|
||
const config = getConfig(); | ||
merge(config, { | ||
httpOptions(url) { | ||
if (url.pathname === '/with-custom-user-agent') { | ||
return { 'user-agent': 'some user agent' }; | ||
} | ||
|
||
return {}; | ||
}, | ||
}); | ||
|
||
export default { | ||
config, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { expect } from 'chai'; | ||
import nock from 'nock'; | ||
|
||
import bootstrap from '../../test_helper.js'; | ||
import request from '../../../lib/helpers/request.js'; | ||
|
||
describe('request helper', () => { | ||
before(bootstrap(import.meta.url)); | ||
|
||
afterEach(nock.cleanAll); | ||
|
||
afterEach(() => { | ||
expect(nock.isDone()).to.be.true; | ||
}); | ||
|
||
describe('when using custom httpOptions', () => { | ||
it('defaults to not sending the user-agent HTTP header', async function () { | ||
nock('https://www.example.com/', { | ||
badheaders: ['user-agent'], | ||
}) | ||
.get('/') | ||
.reply(200); | ||
|
||
await request.call(this.provider, { url: 'https://www.example.com' }); | ||
}); | ||
|
||
it("uses a custom 'user-agent' HTTP header", async function () { | ||
nock('https://www.example.com/', { | ||
reqheaders: { | ||
'user-agent': 'some user agent', | ||
}, | ||
}) | ||
.get('/with-custom-user-agent') | ||
.reply(200); | ||
|
||
await request.call(this.provider, { url: 'https://www.example.com/with-custom-user-agent' }); | ||
}); | ||
}); | ||
}); |