forked from mirrors/gecko-dev
Bug 1736508 - Make TCPSocket work with ipv6 address again. r=valentin
Wrap ipv6 address in [ ] when constructing nsIURI. Differential Revision: https://phabricator.services.mozilla.com/D128843
This commit is contained in:
parent
6c858f9e0c
commit
a2ccfacac3
2 changed files with 26 additions and 0 deletions
|
|
@ -893,9 +893,12 @@ nsresult TCPSocket::ResolveProxy() {
|
|||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsCString spec = mSsl ? "https://"_ns : "http://"_ns;
|
||||
bool maybeIPv6 = mHost.FindChar(':') != -1;
|
||||
if (maybeIPv6) spec.Append('[');
|
||||
if (!AppendUTF16toUTF8(mHost, spec, fallible)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
if (maybeIPv6) spec.Append(']');
|
||||
rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID)
|
||||
.SetSpec(spec)
|
||||
.SetPort(mPort)
|
||||
|
|
|
|||
|
|
@ -589,3 +589,26 @@ async function test_basics() {
|
|||
}
|
||||
|
||||
add_task(test_basics);
|
||||
|
||||
/**
|
||||
* Test that TCPSocket works with ipv6 address.
|
||||
*/
|
||||
add_task(async function test_ipv6() {
|
||||
const { HttpServer } = ChromeUtils.import(
|
||||
"resource://testing-common/httpd.js"
|
||||
);
|
||||
let deferred = defer();
|
||||
let serverPort = 8086;
|
||||
let httpServer = new HttpServer();
|
||||
httpServer.start_ipv6(serverPort);
|
||||
let clientSocket = new TCPSocket("::1", serverPort);
|
||||
clientSocket.onopen = () => {
|
||||
ok(true, "Connect to ipv6 address succeeded");
|
||||
deferred.resolve();
|
||||
};
|
||||
clientSocket.onerror = () => {
|
||||
ok(false, "Connect to ipv6 address failed");
|
||||
deferred.reject();
|
||||
};
|
||||
return deferred.promise;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue