WebExtension 代理 API:解析 SOCKS5 代理上的 DNS 条目(不在本地系统上)

WebExtension proxy API: Resolve DNS entries on SOCKS5 proxy (not on the local system)

Firefox 中的 WebExtension proxy API 是否支持在使用 SOCKS 5 时在代理服务器上解析 DNS?

nsIProtocolProxyService API, which is no longer available in WebExtensions, it was possible. You could pass the flag Components.interfaces.nsIProxyInfo.TRANSPARENT_PROXY_RESOLVES_HOST to nsIProtocolProxyService.newProxyInfo中:

This flag is set if the proxy is to perform name resolution itself. If this is the case, the hostname is used in some fashion, and we shouldn't do any form of DNS lookup ourselves

WebExtensions 的新代理 API 中是否有一些等效选项?

现在 WebExtension API 到 proxy DNS requests 已经成为可能。由于 Bug 1381290 已登陆 Nightly,代理脚本可以 return 对象数组而不是字符串。在提案中,对象具有以下属性:

  • |type| -- string, one of "http"|"https|"socks5"|"socks4"|"socks"|"direct"|"ignore"|. note that "socks" is a synonym for socks5. "ignore" means Firefox should handle this URI through its global proxy settings (which could be wpad, pac, system, direct/none, or a proxy server) or other installed addons.
  • |host| -- string
  • |port| -- integer between 1 and 65536 (TCP/IP does not allow for ports outside that range)
  • |username| -- optional string
  • |password| -- optional string
  • |proxyDNS| -- optional boolean. default false. if true, TRANSPARENT_PROXY_RESOLVES_HOST is set as a flag on nsIProxyInfo.flags so that the proxy server is used to resolve certain DNS queries.
  • |failoverTimeout| -- optional integer. default 1. Number of seconds before timing out and trying the next proxy in the failover array
  • |failover| -- optional array of objects with these same properties. null to terminate. default null (no failover, which is the desired case 99% of the time in my experience).

例如:

{
  type: "socks",
  host: "foo.com",
  port: 1080,
  proxyDNS: true,
  failoverTimeout: 1,
  failover: {
    type: "socks",
    host: "bar.com",
    port: 1080,
    proxyDNS: true,
    failoverTimeout: 0,
    failover: null
  }
}

但是在实际的补丁中,我看不到那个数组中没有 'failover' 选项:

+    for (let prop of ["type", "host", "port", "username", "password", "proxyDNS", "failoverTimeout"]) {
+      this[prop](proxyData);
+    }

而 'failover' 服务器似乎是这样定义的:

+    let failoverProxy = proxyDataList.length > 0 ? this.createProxyInfoFromData(proxyDataList, defaultProxyInfo) : defaultProxyInfo;

相关信息: