2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-11 18:02:32 +03:00

Adding ability to omit User-Agent header (#3703)

* Adding ability to omit User-Agent header

* Update line to be more compact

* Add unit tests for user-agent cases

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Mike Bishop
2021-03-29 10:47:29 -04:00
committed by GitHub
parent c0317b7453
commit b0959f0301
2 changed files with 40 additions and 2 deletions
+31
View File
@@ -7,6 +7,7 @@ var zlib = require('zlib');
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var pkg = require('./../../../package.json');
var server, proxy;
describe('supports http with nodejs', function () {
@@ -879,5 +880,35 @@ describe('supports http with nodejs', function () {
});
});
});
it('should supply a user-agent if one is not specified', function (done) {
server = http.createServer(function (req, res) {
assert.equal(req.headers["user-agent"], 'axios/' + pkg.version);
res.end();
}).listen(4444, function () {
axios.get('http://localhost:4444/'
).then(function (res) {
done();
});
});
});
it('should omit a user-agent if one is explicitly disclaimed', function (done) {
server = http.createServer(function (req, res) {
assert.equal("user-agent" in req.headers, false);
assert.equal("User-Agent" in req.headers, false);
res.end();
}).listen(4444, function () {
axios.get('http://localhost:4444/', {
headers: {
"User-Agent": null
}
}
).then(function (res) {
done();
});
});
});
});