autosel_http_proxy 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 2010-01-25 Kiwamu Okabe <kiwamu@debian.or.jp>
2
+
3
+ * ver.0.0.5
4
+ * lib/autosel_http_proxy.rb: add overwrite_base_class! method.
5
+
1
6
  2010-01-22 Kiwamu Okabe <kiwamu@debian.or.jp>
2
7
 
3
8
  * ver.0.0.4
@@ -1,7 +1,7 @@
1
1
  = AutoselHttpProxy
2
2
 
3
- AutoselHttpProxyは設定ファイルを元にして、HTTP proxyを自動的に設定するユーティリティです。
4
- 設定ファイルを作成した後以下のようにすると、"http_proxy"などの環境変数を設定した状態で任意のコマンドを起動できます。
3
+ AutoselHttpProxyは設定ファイルを元にして、HTTP proxyを自動的に選択設定するユーティリティです。
4
+ 設定ファイルを適切に作成した後以下のようにすると、"http_proxy"などの環境変数を設定した状態で任意のコマンドを起動できます。
5
5
 
6
6
  $ set_httpproxy 任意のコマンド
7
7
 
@@ -9,12 +9,8 @@ AutoselHttpProxyは設定ファイルを元にして、HTTP proxyを自動的に
9
9
 
10
10
  require 'autosel_http_proxy'
11
11
  AutoselHttpProxy::init
12
- if AutoselHttpProxy::setting
13
- p AutoselHttpProxy::setting[:proxy_host] # => proxyホスト名
14
- p AutoselHttpProxy::setting[:proxy_port] # => proxyポート番号
15
- p AutoselHttpProxy::setting[:proxy_user] # => proxy認証ユーザ名
16
- p AutoselHttpProxy::setting[:proxy_pass] # => proxy認証パスワード
17
- end
12
+ AutoselHttpProxy::overwrite_base_class!
13
+ # => この後Net::HTTPを使うとHTTP proxy設定が無理矢理有効になります
18
14
 
19
15
  ノートPCのようにネットワーク環境が頻繁に変更される場合に、本プログラムを使うことでHTTP proxy設定変更の手間が軽減されます。
20
16
 
@@ -27,6 +23,7 @@ gem install autosel_http_proxyでインストールされます。
27
23
 
28
24
  == 設定ファイルの作成
29
25
 
26
+ 本ライブラリは適切に設定ファイルを作成した後に利用可能になります。下記の
30
27
  まずはset_httpproxyコマンドを実行すると、設定ファイルのテンプレートが自動生成されます。
31
28
 
32
29
  $ set_httpproxy
@@ -95,6 +92,15 @@ SHELLの設定ファイルに、aliasを作っておくと楽かもしれませ
95
92
 
96
93
  require 'autosel_http_proxy'
97
94
  AutoselHttpProxy::init
95
+ AutoselHttpProxy::overwrite_base_class!
96
+
97
+ この設定を施すことで、termtterを起動するたびにその時のネットワーク状態から適切なHTTP proxy設定を自動的に検出するようになります。
98
+ ただ、この方式はrubyの基底クラス(Net::HTTP)を無理矢理書き換えてしまうため、あまりおすすめできません。
99
+ ちゃんとHTTP proxyに対応済みのtermtterであれば、以下のようにすれば基底クラス書き換えをせずにHTTP proxy設定できます。
100
+
101
+ require 'autosel_http_proxy'
102
+ AutoselHttpProxy::init
103
+ # AutoselHttpProxy::overwrite_base_class!
98
104
  if AutoselHttpProxy::setting
99
105
  config.proxy.host = AutoselHttpProxy::setting[:proxy_host]
100
106
  config.proxy.port = AutoselHttpProxy::setting[:proxy_port]
@@ -102,7 +108,6 @@ SHELLの設定ファイルに、aliasを作っておくと楽かもしれませ
102
108
  config.proxy.password = AutoselHttpProxy::setting[:proxy_pass]
103
109
  end
104
110
 
105
- この設定を施すことで、termtterを起動するたびにその時のネットワーク状態から適切なHTTP proxy設定を自動的に検出するようになります。
106
111
 
107
112
  == エラーについて
108
113
 
@@ -9,12 +9,7 @@ If you use ruby's program, then can use the below code, to set HTTP proxy settin
9
9
 
10
10
  require 'autosel_http_proxy'
11
11
  AutoselHttpProxy::init
12
- if AutoselHttpProxy::setting
13
- p AutoselHttpProxy::setting[:proxy_host] # => proxy hostname
14
- p AutoselHttpProxy::setting[:proxy_port] # => proxy port number
15
- p AutoselHttpProxy::setting[:proxy_user] # => proxy username
16
- p AutoselHttpProxy::setting[:proxy_pass] # => proxy password
17
- end
12
+ AutoselHttpProxy::overwrite_base_class!
18
13
 
19
14
  == Usage and Detail
20
15
 
@@ -2,12 +2,13 @@
2
2
  require 'resolv'
3
3
 
4
4
  module AutoselHttpProxy
5
- VERSION = '0.0.4'
5
+ VERSION = '0.0.5'
6
6
  PROXY_CONFFILE = File.expand_path '~/.autosel_http_proxy.conf'
7
7
 
8
8
  class ConfigNotFound < RuntimeError; end
9
9
  class ConfigNotConfigured < RuntimeError; end
10
10
  class NeedHostname < RuntimeError; end
11
+ class DoubleCallOverwrite < RuntimeError; end
11
12
 
12
13
  class Setting
13
14
  @@proxy_url = nil
@@ -87,11 +88,36 @@ EOF
87
88
  init_proxy_setting PROXY_LIST
88
89
  set_proxy_env!
89
90
  end
91
+
92
+ def self.overwrite_base_class!
93
+ require 'net/http'
94
+
95
+ Net::HTTP.instance_eval {
96
+ if defined? @@method_new_orig
97
+ raise DoubleCallOverwrite
98
+ end
99
+ @@method_new_orig = self.method(:new) # backup orignal 'new' method
100
+
101
+ def new(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil)
102
+ # overwrite!
103
+ if AutoselHttpProxy::setting
104
+ p_addr = AutoselHttpProxy::setting[:proxy_host]
105
+ p_port = AutoselHttpProxy::setting[:proxy_port]
106
+ p_user = AutoselHttpProxy::setting[:proxy_user]
107
+ p_pass = AutoselHttpProxy::setting[:proxy_pass]
108
+ end
109
+
110
+ # call orignal 'new' method
111
+ @@method_new_orig.call(address, port, p_addr, p_port, p_user, p_pass)
112
+ end
113
+ }
114
+ end
90
115
  end
91
116
 
92
117
  class << self
93
118
  def url() Setting.proxy_url end
94
119
  def setting() Setting.proxy_setting end
95
120
  def init() Setting.init end
121
+ def overwrite_base_class!() Setting.overwrite_base_class! end
96
122
  end
97
123
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autosel_http_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kiwamu Okabe
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-22 00:00:00 +09:00
12
+ date: 2010-01-25 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15