Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Commit

Permalink
Bug 1601671 - make websocket support proxying on SOCKS/HTTPS, r=michal
Browse files Browse the repository at this point in the history
This is something less hacky to the best of my knowledge. Both passing preferable proxy table and letting system setting handle `ws`/`wss` touch the code of all platforms, which is more fragile.

Differential Revision: https://phabricator.services.mozilla.com/D57176

--HG--
extra : moz-landing-system : lando
  • Loading branch information
JuniorHsu committed Dec 24, 2019
1 parent d5fe331 commit bc6a80e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
21 changes: 20 additions & 1 deletion netwerk/base/nsProtocolProxyService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,26 @@ nsresult nsProtocolProxyService::Resolve_Internal(nsIChannel* channel,
// now try the system proxy settings for this particular url
if (NS_SUCCEEDED(mSystemProxySettings->GetProxyForURI(spec, scheme, host,
port, pacString))) {
ProcessPACString(pacString, 0, result);
nsCOMPtr<nsIProxyInfo> pi;
ProcessPACString(pacString, 0, getter_AddRefs(pi));

if (flags & RESOLVE_PREFER_SOCKS_PROXY &&
flags & RESOLVE_PREFER_HTTPS_PROXY) {
nsAutoCString type;
pi->GetType(type);
// DIRECT from ProcessPACString indicates that system proxy settings
// are not configured to use SOCKS proxy. Try https proxy as a
// secondary preferrable proxy. This is mainly for websocket whose
// proxy precedence is SOCKS > HTTPS > DIRECT.
if (type.EqualsLiteral(kProxyType_DIRECT)) {
scheme.AssignLiteral(kProxyType_HTTPS);
if (NS_SUCCEEDED(mSystemProxySettings->GetProxyForURI(
spec, scheme, host, port, pacString))) {
ProcessPACString(pacString, 0, getter_AddRefs(pi));
}
}
}
pi.forget(result);
return NS_OK;
}
}
Expand Down
37 changes: 34 additions & 3 deletions netwerk/test/unit/test_bug1177909.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ XPCOMUtils.defineLazyGetter(this, "systemSettings", function() {
if (aPort != -1) {
return "SOCKS5 http://localhost:9050";
}
if (aScheme == "http" || aScheme == "https" || aScheme == "ftp") {
if (aScheme == "http" || aScheme == "ftp") {
return "PROXY http://localhost:8080";
}
if (aScheme == "https") {
return "HTTPS https://localhost:8080";
}
return "DIRECT";
},
};
Expand Down Expand Up @@ -79,7 +82,7 @@ add_task(async function testHttpsProxy() {
let pi = await TestProxyTypeByURI("https://www.mozilla.org/");
equal(pi.host, "localhost", "Expected proxy host to be localhost");
equal(pi.port, 8080, "Expected proxy port to be 8080");
equal(pi.type, "http", "Expected proxy type to be http");
equal(pi.type, "https", "Expected proxy type to be https");
});

add_task(async function testFtpProxy() {
Expand Down Expand Up @@ -137,6 +140,7 @@ add_task(async function testWebSocketProxy() {
.finalize();

let proxyFlags =
Ci.nsIProtocolProxyService.RESOLVE_PREFER_SOCKS_PROXY |
Ci.nsIProtocolProxyService.RESOLVE_PREFER_HTTPS_PROXY |
Ci.nsIProtocolProxyService.RESOLVE_ALWAYS_TUNNEL;

Expand All @@ -157,5 +161,32 @@ add_task(async function testWebSocketProxy() {
let pi = await TestProxyType(chan, proxyFlags);
equal(pi.host, "localhost", "Expected proxy host to be localhost");
equal(pi.port, 8080, "Expected proxy port to be 8080");
equal(pi.type, "http", "Expected proxy type to be http");
equal(pi.type, "https", "Expected proxy type to be https");
});

add_task(async function testPreferHttpsProxy() {
let uri = Cc["@mozilla.org/network/standard-url-mutator;1"]
.createInstance(Ci.nsIURIMutator)
.setSpec("http://mozilla.org/")
.finalize();
let proxyFlags = Ci.nsIProtocolProxyService.RESOLVE_PREFER_HTTPS_PROXY;

let ioService = Cc["@mozilla.org/network/io-service;1"].getService(
Ci.nsIIOService
);
let chan = ioService.newChannelFromURIWithProxyFlags(
uri,
null,
proxyFlags,
null,
Services.scriptSecurityManager.getSystemPrincipal(),
null,
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
Ci.nsIContentPolicy.TYPE_OTHER
);

let pi = await TestProxyType(chan, proxyFlags);
equal(pi.host, "localhost", "Expected proxy host to be localhost");
equal(pi.port, 8080, "Expected proxy port to be 8080");
equal(pi.type, "https", "Expected proxy type to be https");
});

0 comments on commit bc6a80e

Please sign in to comment.