| 1 |
|
| 2 |
|
| 3 |
require 'net/http' |
| 4 |
|
| 5 |
module Net |
| 6 |
class << HTTP |
| 7 |
extend Memoist |
| 8 |
|
| 9 |
alias new_org new |
| 10 |
def new(host, port=80, proxy_addr=nil, proxy_port=nil, proxy_user=nil, proxy_pass=nil) |
| 11 |
case UserConfig[:proxy_enabled] |
| 12 |
when :specify |
| 13 |
pu, pp = nil, nil |
| 14 |
pu, pp = UserConfig[:proxy_user], UserConfig[:proxy_password] if UserConfig[:proxy_cert] |
| 15 |
|
| 16 |
new_org(host, port, UserConfig[:proxy_server], UserConfig[:proxy_port].to_i, pu, pp) |
| 17 |
when :disable |
| 18 |
new_org(host, port) |
| 19 |
else |
| 20 |
new_org(host, port, *get_env_proxy_settings) end end |
| 21 |
|
| 22 |
def get_env_proxy_settings |
| 23 |
env_proxy_settings = ENV.fetch('HTTP_PROXY', '').sub(/http:\/\//, '').split(/[@:]/) |
| 24 |
case(env_proxy_settings.size) |
| 25 |
when 2 |
| 26 |
[env_proxy_settings[0], env_proxy_settings[1].to_i] |
| 27 |
when 4 |
| 28 |
[env_proxy_settings[2], env_proxy_settings[3].to_i, env_proxy_settings[0], env_proxy_settings[1]] |
| 29 |
else |
| 30 |
[] end end |
| 31 |
end |
| 32 |
end |
| 33 |
|
| 34 |
Plugin::create(:proxy) do |
| 35 |
settings _("プロキシ") do |
| 36 |
select _("プロキシ"), :proxy_enabled do |
| 37 |
option :specify, _("自分で設定する") do |
| 38 |
input _("サーバ"), :proxy_server |
| 39 |
adjustment _("ポート"), :proxy_port, 1, 65535 |
| 40 |
input _("ユーザ"), :proxy_user |
| 41 |
inputpass _("パスワード"), :proxy_password |
| 42 |
boolean _("ユーザ認証が必要"), :proxy_cert |
| 43 |
end |
| 44 |
option :disable, _("環境変数の設定を使う") |
| 45 |
option nil, _("プロキシを使わない") |
| 46 |
end |
| 47 |
end |
| 48 |
end |