mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
fix(http): fixed support for IPv6 literal strings in url (#5731)
This commit is contained in:
@@ -427,7 +427,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|||||||
if (config.socketPath) {
|
if (config.socketPath) {
|
||||||
options.socketPath = config.socketPath;
|
options.socketPath = config.socketPath;
|
||||||
} else {
|
} else {
|
||||||
options.hostname = parsed.hostname;
|
options.hostname = parsed.hostname.startsWith("[") ? parsed.hostname.slice(1, -1) : parsed.hostname;
|
||||||
options.port = parsed.port;
|
options.port = parsed.port;
|
||||||
setProxy(options, config.proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
|
setProxy(options, config.proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,6 +159,44 @@ describe('supports http with nodejs', function () {
|
|||||||
delete process.env.no_proxy;
|
delete process.env.no_proxy;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should support IPv4 literal strings', function (done) {
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
firstName: 'Fred',
|
||||||
|
lastName: 'Flintstone',
|
||||||
|
emailAddr: 'fred@example.com'
|
||||||
|
};
|
||||||
|
|
||||||
|
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: 'fred@example.com'
|
||||||
|
};
|
||||||
|
|
||||||
|
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) {
|
it('should throw an error if the timeout property is not parsable as a number', function (done) {
|
||||||
|
|
||||||
server = http.createServer(function (req, res) {
|
server = http.createServer(function (req, res) {
|
||||||
|
|||||||
Reference in New Issue
Block a user