Skip to content

Commit

Permalink
Merge pull request #539 from ozzywalsh/fix-agent-defaults
Browse files Browse the repository at this point in the history
Call this._setDefaults to set agent defaults
  • Loading branch information
rimiti committed Mar 9, 2019
2 parents 5914936 + 3b13e91 commit abf6bc3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/agent.js
Expand Up @@ -58,6 +58,7 @@ methods.forEach(function(method) {
req.on('redirect', this._saveCookies.bind(this));
req.on('redirect', this._attachCookies.bind(this, req));
this._attachCookies(req);
this._setDefaults(req);

return req;
};
Expand Down
18 changes: 15 additions & 3 deletions test/supertest.js
Expand Up @@ -832,7 +832,8 @@ describe('request(app)', function () {

describe('request.agent(app)', function () {
const app = express();
const agent = request.agent(app);
const agent = request.agent(app)
.set('header', 'hey');

app.use(cookieParser());

Expand All @@ -841,11 +842,16 @@ describe('request.agent(app)', function () {
res.send();
});

app.get('/return', function (req, res) {
app.get('/return_cookies', function (req, res) {
if (req.cookies.cookie) res.send(req.cookies.cookie);
else res.send(':(');
});

app.get('/return_headers', function (req, res) {
if (req.get('header')) res.send(req.get('header'));
else res.send(':(');
});

it('should save cookies', function (done) {
agent
.get('/')
Expand All @@ -854,7 +860,13 @@ describe('request.agent(app)', function () {

it('should send cookies', function (done) {
agent
.get('/return')
.get('/return_cookies')
.expect('hey', done);
});

it('should send global agent headers', function (done) {
agent
.get('/return_headers')
.expect('hey', done);
});
});
Expand Down

0 comments on commit abf6bc3

Please sign in to comment.