Backed out changeset 0ce17eb985f1 (bug 1406763)

This commit is contained in:
Sebastian Hengst 2017-10-12 20:51:38 +02:00
Родитель a19b8a7f82
Коммит 1237c730d7
2 изменённых файлов: 10 добавлений и 48 удалений

Просмотреть файл

@ -196,10 +196,6 @@ session.Proxy = class {
* When proxy configuration is invalid.
*/
static fromJSON(json) {
function stripBracketsFromIpv6Hostname(hostname) {
return hostname.includes(":") ? hostname.replace(/[\[\]]/g, "") : hostname;
}
// Parse hostname and optional port from host
function fromHost(scheme, host) {
assert.string(host);
@ -223,8 +219,6 @@ session.Proxy = class {
throw new InvalidArgumentError(e.message);
}
let hostname = stripBracketsFromIpv6Hostname(url.hostname);
// If the port hasn't been set, use the default port of
// the selected scheme (except for socks which doesn't have one).
let port = parseInt(url.port);
@ -245,7 +239,7 @@ session.Proxy = class {
`${host} was not of the form host[:port]`);
}
return [hostname, port];
return [url.hostname, port];
}
let p = new session.Proxy();
@ -284,10 +278,10 @@ session.Proxy = class {
}
if (typeof json.noProxy != "undefined") {
let entries = assert.array(json.noProxy);
p.noProxy = entries.map(entry => {
for (let entry of entries) {
assert.string(entry);
return stripBracketsFromIpv6Hostname(entry);
});
}
p.noProxy = entries;
}
break;
@ -304,18 +298,11 @@ session.Proxy = class {
* JSON serialisation of proxy object.
*/
toJSON() {
function addBracketsToIpv6Hostname(hostname) {
return hostname.includes(":") ? `[${hostname}]` : hostname;
}
function toHost(hostname, port) {
if (!hostname) {
return null;
}
// Add brackets around IPv6 addresses
hostname = addBracketsToIpv6Hostname(hostname)
if (port != null) {
return `${hostname}:${port}`;
}
@ -323,16 +310,11 @@ session.Proxy = class {
return hostname;
}
let excludes = this.noProxy;
if (excludes) {
excludes = excludes.map(addBracketsToIpv6Hostname);
}
return marshal({
proxyType: this.proxyType,
ftpProxy: toHost(this.ftpProxy, this.ftpProxyPort),
httpProxy: toHost(this.httpProxy, this.httpProxyPort),
noProxy: excludes,
noProxy: this.noProxy,
sslProxy: toHost(this.sslProxy, this.sslProxyPort),
socksProxy: toHost(this.socksProxy, this.socksProxyPort),
socksVersion: this.socksVersion,

Просмотреть файл

@ -223,22 +223,8 @@ add_test(function test_Proxy_toJSON() {
p[`${proxy}Port`] = 42;
expected[proxy] = "foo:42"
deepEqual(p.toJSON(), expected);
// add brackets for IPv6 address as proxy hostname
p[proxy] = "2001:db8::1";
p[`${proxy}Port`] = 42;
expected[proxy] = "foo:42"
expected[proxy] = "[2001:db8::1]:42";
deepEqual(p.toJSON(), expected);
}
// noProxy: add brackets for IPv6 address
p = new session.Proxy();
p.proxyType = "manual";
p.noProxy = ["2001:db8::1"];
let expected = {proxyType: "manual", noProxy: "[2001:db8::1]"};
deepEqual(p.toJSON(), expected);
run_next_test();
});
@ -299,7 +285,7 @@ add_test(function test_Proxy_fromJSON() {
"foo:443": {hostname: "foo", port: 443},
"foo:65535": {hostname: "foo", port: 65535},
"127.0.0.1:42": {hostname: "127.0.0.1", port: 42},
"[2001:db8::1]:42": {hostname: "2001:db8::1", port: "42"},
"[2001:db8::1]:42": {hostname: "[2001:db8::1]", port: "42"},
};
// valid proxy hosts with port
@ -336,7 +322,7 @@ add_test(function test_Proxy_fromJSON() {
{proxyType: "manual", socksProxy: "foo:1234"}),
InvalidArgumentError);
// noProxy: invalid settings
// invalid noProxy
for (let noProxy of [true, 42, {}, null, "foo",
[true], [42], [{}], [null]]) {
Assert.throws(() => session.Proxy.fromJSON(
@ -344,22 +330,16 @@ add_test(function test_Proxy_fromJSON() {
InvalidArgumentError);
}
// noProxy: valid settings
// valid noProxy
p = new session.Proxy();
p.proxyType = "manual";
for (let noProxy of [[], ["foo"], ["foo", "bar"], ["127.0.0.1"]]) {
for (let noProxy of [[], ["foo"], ["foo", "bar"],
["127.0.0.1"], ["[2001:db8::1"]]) {
let manual = {proxyType: "manual", "noProxy": noProxy}
p.noProxy = noProxy;
deepEqual(p, session.Proxy.fromJSON(manual));
}
// noProxy: IPv6 needs brackets removed
p = new session.Proxy();
p.proxyType = "manual";
p.noProxy = ["2001:db8::1"];
let manual = {proxyType: "manual", "noProxy": ["[2001:db8::1]"]}
deepEqual(p, session.Proxy.fromJSON(manual));
run_next_test();
});