Skip to content

Commit

Permalink
fix(http): fixed support for IPv6 literal strings in url (axios#5731)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishi556 authored Aug 31, 2024
1 parent d198085 commit 364993f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/adapters/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
if (config.socketPath) {
options.socketPath = config.socketPath;
} else {
options.hostname = parsed.hostname;
options.hostname = parsed.hostname.startsWith("[") ? parsed.hostname.slice(1, -1) : parsed.hostname;
options.port = parsed.port;
setProxy(options, config.proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
}
Expand Down
38 changes: 38 additions & 0 deletions test/unit/adapters/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,44 @@ describe('supports http with nodejs', function () {
delete process.env.no_proxy;
});

it('should support IPv4 literal strings', function (done) {

var data = {
firstName: 'Fred',
lastName: 'Flintstone',
emailAddr: '[email protected]'
};

server = http.createServer(function (req, res) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(data));
}).listen(4444, function () {
axios.get('http://127.0.0.1:4444/').then(function (res) {
assert.deepEqual(res.data, data);
done();
}).catch(done);
});
});

it('should support IPv6 literal strings', function (done) {

var data = {
firstName: 'Fred',
lastName: 'Flintstone',
emailAddr: '[email protected]'
};

server = http.createServer(function (req, res) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(data));
}).listen(4444, function () {
axios.get('http://[::1]:4444/').then(function (res) {
assert.deepEqual(res.data, data);
done();
}).catch(done);
});
});

it('should throw an error if the timeout property is not parsable as a number', function (done) {

server = http.createServer(function (req, res) {
Expand Down

0 comments on commit 364993f

Please sign in to comment.