FelisCatus / switchysharp

Automatically exported from code.google.com/p/switchysharp
GNU General Public License v3.0
140 stars 50 forks source link

只配置https代理,却走了http协议 #885

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
!! 请勿清空此模板,除非你不希望问题被解决。

*提示* :请确认你正在使用最新版的 SwitchySharp 插件。
你可以在扩展管理页面的“开发人员模式”中点击
“立即更新扩展”按钮来更新。
----------

你遇到了什么问题?(比如,本来应该是怎样的结果,但
实际又是怎样的结果?):

如何重现此问题?(怎样做可以发现这个问题?):
1.手动配置里只填写https代理+端口;
2.保存;
3.实际上代理没有走https协议;

具体代码如下,只配置https代理,proxy.scheme无法设置成'https'��
�最终只走http协议。

#plugin.js

#223行
if (profile.proxyHttps)
    config.rules.proxyForHttps = ProxyPlugin._parseProxy(profile.proxyHttps);
}

#137行
ProxyPlugin._parseProxy = function (str) {
    if (str) {
        var proxy = {scheme:'http', host:'', port:80};
        var t1 = null;
        var t = str.indexOf(']') + 1;
        if (t > 0) {
            t1 = new Array();
            t1.push(proxy.host = str.substr(0, t));
            if (t < str.length - 1)
                t1.push(str.substr(t + 1));
        }
        else {
            t1 = str.split(':');
            proxy.host = t1[0];
        }
        var t2 = proxy.host.split('=');
        if (t2.length > 1) {
            proxy.scheme = t2[0] == 'socks' ? 'socks4' : t2[0];
            proxy.host = t2[1];
        }
        if (t1.length > 1)
            proxy.port = parseInt(t1[1]);
        return proxy;
    }
    else
        return {}
};

你正在使用什么操作系统和 Chrome/Chromium 的什么版本?
(你可以复制 chrome://version/ 页面的前几行。)

Google Chrome   32.0.1700.107 (正式版本 248368) m
操作系统    Windows 
Blink   537.36 (@165586)

建议附上你的设置备份文件(.bak)以便分析问题:
* 设置备份文件可在“导入/导出”选项卡使用
“生成备份文件”按钮导出。
* 请使用下面的上传附件功能,将自动下载的备份文件
(.bak)和你的报告一起提交。

我简单修改了一下就可以用了,修改如下:
/*
 Copyright (c) 2011 Shyc2001 (http://twitter.com/shyc2001)
 This work is based on:
 *"Switchy! Chrome Proxy Manager and Switcher" (by Mohammad Hejazi (mohammadhi at gmail d0t com))
 *"SwitchyPlus" by @ayanamist (http://twitter.com/ayanamist)

 This file is part of SwitchySharp.
 SwitchySharp is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 SwitchySharp is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with SwitchySharp.  If not, see <http://www.gnu.org/licenses/>.
 */
var memoryPath = ':memory:';
var ProxyPlugin = {};
ProxyPlugin.memoryPath = memoryPath;
ProxyPlugin.proxyMode = Settings.getValue('proxyMode', 'direct');
ProxyPlugin.proxyServer = Settings.getValue('proxyServer', '');
ProxyPlugin.proxyExceptions = Settings.getValue('proxyExceptions', '');
ProxyPlugin.proxyConfigUrl = Settings.getValue('proxyConfigUrl', '');
ProxyPlugin.autoPacScriptPath = Settings.getValue('autoPacScriptPath', '');
ProxyPlugin.mute = false;
ProxyPlugin.init = function () {
    if (chrome.experimental !== undefined && chrome.experimental.proxy !== undefined)
        ProxyPlugin._proxy = chrome.experimental.proxy;
    else if (chrome.proxy !== undefined)
        ProxyPlugin._proxy = chrome.proxy;
    else
        alert('Need proxy api support, please update your Chrome');
    ProxyPlugin._proxy.settings.onChange.addListener(ProxyPlugin.updateProxy);
    ProxyPlugin._proxy.settings.get({}, ProxyPlugin.updateProxy);
};

ProxyPlugin.updateProxy = function (config) {
    if (ProxyPlugin.mute) return;
    if (config.value) {
        config = config.value;
    }
    switch (config.mode) {
        case 'system':
            ProxyPlugin.proxyMode = Settings.setValue('proxyMode', 'system');
            ProxyPlugin.proxyServer = Settings.setValue('proxyServer', '');
            ProxyPlugin.proxyExceptions = Settings.setValue('proxyExceptions', '');
            ProxyPlugin.proxyConfigUrl = Settings.setValue('proxyConfigUrl', '');
            break;
        case 'direct':
            ProxyPlugin.proxyMode = Settings.setValue('proxyMode', 'direct');
            ProxyPlugin.proxyServer = Settings.setValue('proxyServer', '');
            ProxyPlugin.proxyExceptions = Settings.setValue('proxyExceptions', '');
            ProxyPlugin.proxyConfigUrl = Settings.setValue('proxyConfigUrl', '');
            break;
        case 'fixed_servers':
            ProxyPlugin.proxyMode = Settings.setValue('proxyMode', 'manual');
            var profile = {
                useSameProxy:false,
                proxyHttp:'',
                proxyHttps:'',
                proxyFtp:'',
                proxySocks:'',
                socksVersion:4
            };
            if (config.rules.singleProxy) {
                var proxyString = config.rules.singleProxy.host + ':' + config.rules.singleProxy.port;
                if (config.rules.singleProxy.scheme == 'http') {
                    profile.useSameProxy = true;
                    profile.proxyHttp = proxyString;
                }
                else {
                    switch (config.rules.singleProxy.scheme) {
                        case 'socks4':
                            profile.socksVersion = 4;
                            profile.proxySocks = proxyString;
                            break;
                        case 'socks5':
                            profile.socksVersion = 5;
                            profile.proxySocks = proxyString;
                            break;
                        case 'https':
                            profile.proxyHttps = proxyString;
                            break;
                    }
                }
            }
            else {
                if (config.rules.proxyForHttp) {
                    profile.proxyHttp = config.rules.proxyForHttp.host + ':' + config.rules.proxyForHttp.port;
                }
                if (config.rules.proxyForHttps) {
                    profile.proxyHttps = config.rules.proxyForHttps.host + ':' + config.rules.proxyForHttps.port;
                }
                if (config.rules.proxyForFtp) {
                    profile.proxyFtp = config.rules.proxyForFtp.host + ':' + config.rules.proxyForFtp.port;
                }
                if (config.rules.fallbackProxy) {
                    if (config.rules.fallbackProxy.scheme == 'socks4')
                        profile.socksVersion = 4;
                    else
                        profile.socksVersion = 5;
                    profile.proxySocks = config.rules.fallbackProxy.host + ':' + config.rules.fallbackProxy.port;
                }
            }
            ProxyPlugin.proxyServer = Settings.setValue('proxyServer', ProfileManager.buildProxyString(profile));
            profile = null;
            ProxyPlugin.proxyExceptions = Settings.setValue('proxyExceptions',
                config.rules.bypassList ? config.rules.bypassList.join(';') : '');
            ProxyPlugin.proxyConfigUrl = Settings.setValue('proxyConfigUrl', '');
            break;
        case 'pac_script':
            ProxyPlugin.proxyMode = Settings.setValue('proxyMode', 'auto');
            if (config.pacScript.url !== undefined) {
                ProxyPlugin.proxyConfigUrl = Settings.setValue('proxyConfigUrl', config.pacScript.url);
                ProxyPlugin.autoPacScriptPath = Settings.setValue('autoPacScriptPath', config.pacScript.url);
            }
            else {
                ProxyPlugin.proxyConfigUrl = Settings.setValue('proxyConfigUrl', memoryPath);
                ProxyPlugin.autoPacScriptPath = Settings.setValue('autoPacScriptPath', memoryPath);
            }
            break;
    }

    if (ProxyPlugin.updateProxyCallback != undefined) {
        ProxyPlugin.updateProxyCallback();
        ProxyPlugin.updateProxyCallback = undefined;
    }
    else if (Settings.getValue("monitorProxyChanges", true))
        setIconInfo(undefined, Settings.getValue("preventProxyChanges", false));

};

ProxyPlugin._parseProxy = function (str) {
    if (str) {
        var proxy = {scheme:'http', host:'', port:80};
        var t1 = null;
        var t = str.indexOf(']') + 1;
        if (t > 0) {
            t1 = new Array();
            t1.push(proxy.host = str.substr(0, t));
            if (t < str.length - 1)
                t1.push(str.substr(t + 1));
        }
        else {
            t1 = str.split(':');
            proxy.host = t1[0];
        }
        var t2 = proxy.host.split('=');
        if (t2.length > 1) {
            proxy.scheme = t2[0] == 'socks' ? 'socks4' : t2[0];
            proxy.host = t2[1];
        }
        if (t1.length > 1)
            proxy.port = parseInt(t1[1]);
        return proxy;
    }
    else
        return {}
};
ProxyPlugin.setProxy = function (proxyMode, proxyString, proxyExceptions, 
proxyConfigUrl) {
    var config;
    ProxyPlugin.proxyMode = Settings.setValue('proxyMode', proxyMode);
    ProxyPlugin.proxyServer = Settings.setValue('proxyServer', proxyString);
    ProxyPlugin.proxyExceptions = Settings.setValue('proxyExceptions', proxyExceptions);
    ProxyPlugin.proxyConfigUrl = Settings.setValue('proxyConfigUrl', proxyConfigUrl);
    switch (proxyMode) {
        case 'system':
            config = {mode:"system"};
            break;
        case 'direct':
            config = {mode:"direct"};
            break;
        case 'manual':
            var tmpbypassList = [];
            var proxyExceptionsList = ProxyPlugin.proxyExceptions.split(';');
            var proxyExceptionListLength = proxyExceptionsList.length;
            for (var i = 0; i < proxyExceptionListLength; i++) {
                tmpbypassList.push(proxyExceptionsList[i].trim())
            }
            proxyExceptionsList = null;
            var profile = ProfileManager.parseProxyString(proxyString);
            if (profile.useSameProxy) {
                config = {
                    mode:"fixed_servers",
                    rules:{
                        singleProxy:ProxyPlugin._parseProxy(profile.proxyHttp),
                        bypassList:tmpbypassList
                    }
                };
            }
            else {
                var socksProxyString;
                if (profile.proxySocks && !profile.proxyHttp && !profile.proxyFtp && !profile.proxyHttps) {
                    socksProxyString = profile.socksVersion == 4 ? 'socks=' + profile.proxySocks : 'socks5=' + profile.proxySocks;
                    config = {
                        mode:"fixed_servers",
                        rules:{
                            singleProxy:ProxyPlugin._parseProxy(socksProxyString),
                            bypassList:tmpbypassList
                        }
                    }

                }
                else {
                    config = {
                        mode:"fixed_servers",
                        rules:{
                            bypassList:tmpbypassList
                        }
                    };
                    if (profile.proxySocks) {
                        socksProxyString = profile.socksVersion == 4 ? 'socks=' + profile.proxySocks : 'socks5=' + profile.proxySocks;
                        config.rules.fallbackProxy = ProxyPlugin._parseProxy(socksProxyString);
                    }
                    if (profile.proxyHttp)
                        config.rules.proxyForHttp = ProxyPlugin._parseProxy(profile.proxyHttp);
                    if (profile.proxyFtp)
                        config.rules.proxyForFtp = ProxyPlugin._parseProxy(profile.proxyFtp);
                    if (profile.proxyHttps)
                        config.rules.proxyForHttps = ProxyPlugin._parseProxy(profile.proxyHttps);
                }
            }
            tmpbypassList = null;
            break;
        case 'auto':
            if (ProxyPlugin.proxyConfigUrl == memoryPath) {
                config = {
                    mode:"pac_script",
                    pacScript:{
                        data:Settings.getValue('pacScriptData', '')
                    }
                };
                Settings.setValue('pacScriptData', '');
            }
            else {
                config = {
                    mode:"pac_script",
                    pacScript:{
                        url:ProxyPlugin.proxyConfigUrl
                    }
                }
            }
            break;
    }
    ProxyPlugin.mute = true;
    ProxyPlugin._proxy.settings.set({'value':config}, function () {
        ProxyPlugin.mute = false;
        if (ProxyPlugin.setProxyCallback != undefined) {
            ProxyPlugin.setProxyCallback();
            ProxyPlugin.setProxyCallback = undefined;
        }
    });
    profile = null;
    config = null;
    return 0;
};
ProxyPlugin.writeAutoPacFile = function (script) {
    ProxyPlugin.autoPacScriptPath = Settings.setValue('autoPacScriptPath', memoryPath);
    Settings.setValue('pacScriptData', script);
    return 0;
};

感谢你的支持。
开发人员可能会对此错误的细节进行进一步的询问,或说
明问题已经修复,请及时查收 *邮件* 以获取最新消息。

Original issue reported on code.google.com by lzj....@gmail.com on 6 Mar 2014 at 10:35

GoogleCodeExporter commented 9 years ago
代码贴错了,贴成你的原始代码了,修改后的文件在附件里

Original comment by lzj....@gmail.com on 6 Mar 2014 at 10:41

Attachments:

GoogleCodeExporter commented 9 years ago
SwitchySharp 
没有区分代理的协议和网址的协议,所以说不能做太多这样��
�更改呢。

在新版的 SwitchyOmega 里可以正常使用 HTTPS 
代理服务器,并且可以代理任意URL scheme 的请求。

您的修改版可以先自己使用,不过估计是不太可能会合并到��
�在的版本中,可能会导致不少问题,而且 PAC 
脚本生成那边也没有做相应的处理。所以就暂时不做合并了��
�请谅解。

另外能不能请您贴一下 diff 或者 patch 
?代码本身太长了(11.4KB),也许我们可以集中关注一下修��
�过的几行,看看是否有更好的解决方式。

Original comment by shyc2...@gmail.com on 6 Mar 2014 at 10:59

GoogleCodeExporter commented 9 years ago
我的代理服务器是https的哈~
diff见附件

Original comment by lzj....@gmail.com on 6 Mar 2014 at 1:04

Attachments:

GoogleCodeExporter commented 9 years ago
您这个修改虽然对于您自己的设置情况是可行的,但是对于��
�如说需要对 HTTPS 网址采用 HTTP 
代理的情况,这个更改会让那些设置无法工作。

其根本原因,再强调一次,在于 SwitchySharp 
没有区分代理的协议和网址的协议。在设置中,无法分别设��
�网址的协议和代理本身的协议,才会导致这种问题。

在新版的 SwitchyOmega 里可以正常使用 HTTPS 
代理服务器,所以请您先用那个吧。

Original comment by shyc2...@gmail.com on 7 Mar 2014 at 6:30