2006-02-11 現在、openomyfs (0.1) は proxy 経由の openomy アクセスをサポートしていない。そこで、ちょこっとパッチを書いてみた。この記事の末尾に置いたので、コピペで openomyfs.diff という名前で保存し、
$ cd ~/bin (~/bin に ofs.rb があるとして) $ patch < openomyfs.diff
として下され。
proxy は環境変数 http_proxy に設定する。例えば proxy.foo.net で 8080 ポートを使うなら、.bashrc に次の一行を追加する。
export http_proxy='http://proxy.foo.net:8080/'
ref
=== modified file 'ofs.rb'
--- ofs.rb
+++ ofs.rb
@@ -25,6 +25,9 @@
require 'openomy'
require 'yaml'
require 'net/http'
+
+Net::HTTP.version_1_2
+
class Cache
@@ -416,7 +419,7 @@
# get the file from openomy
def download_file(f)
uri = URI.parse f.downloadlink
- return Net::HTTP.get(uri)
+ return Net::HTTP::Proxy($proxy_addr, $proxy_port).get(uri)
end
################################ file/directory types
@@ -532,7 +535,8 @@
ct_filename ||= "#{ENV["HOME"]}/.ofs.yml"
if File.exists?(ct_filename)
- data = YAML.load_file(ct_filename)
+ dat = File.open(ct_filename)
+ data = YAML.load(dat)
if data && data["ct"]
ret = data["ct"]
return ret
=== modified file 'openomy.rb'
--- openomy.rb
+++ openomy.rb
@@ -49,6 +49,15 @@
require "yaml"
require "rexml/document"
require "rexml/streamlistener"
+
+Net::HTTP.version_1_2
+
+if proxy = ENV['http_proxy']
+ proxy = URI.parse(proxy)
+ $proxy_addr = proxy.host
+ $proxy_port = proxy.port
+end
+
module OpenomyParser
@@ -332,7 +341,7 @@
def get_request(params)
uri = @@apipath + "?" + gen_querystring(fill_params(params))
- h = Net::HTTP.new(OpenomyAPI.server, 80)
+ h = Net::HTTP::Proxy($proxy_addr, $proxy_port).new(OpenomyAPI.server, 80)
h.set_debug_output $stdout if @@debug
return h.start() { |http|
response = http.get(uri, { "User-Agent" => OpenomyAPI.useragent})
@@ -516,7 +525,7 @@
query, header = prepare_query(remotefilename, params, data, boundary)
- h = Net::HTTP.new(OpenomyAPI.server, 80)
+ h = Net::HTTP::Proxy($proxy_addr, $proxy_port).new(OpenomyAPI.server, 80)
h.set_debug_output $stdout if @@debug
return h.start() { |http|
response = http.post(OpenomyAPI.apipath, query, header)
0 件のコメント:
コメントを投稿