class Pione::Location::HTTPLocation
Public Instance Methods
copy(dest, option={})
click to toggle source
# File lib/pione/location/http-location.rb, line 36 def copy(dest, option={}) # setup options option[:keep_mtime] = true if option[:keep_mtime].nil? # copy http_get {|rec| dest.write rec.body} # modify mtime dest.mtime = self.mtime if option[:keep_mtime] end
directory?()
click to toggle source
# File lib/pione/location/http-location.rb, line 32 def directory? false end
exist?()
click to toggle source
# File lib/pione/location/http-location.rb, line 22 def exist? http_head {|res| true} rescue false end
file?()
click to toggle source
# File lib/pione/location/http-location.rb, line 28 def file? exist? end
mtime()
click to toggle source
# File lib/pione/location/http-location.rb, line 14 def mtime http_head {|res| Time.httpdate(res['last-modified']) } end
read()
click to toggle source
# File lib/pione/location/http-location.rb, line 10 def read http_get {|res| res.body} end
size()
click to toggle source
# File lib/pione/location/http-location.rb, line 18 def size http_head {|res| res.content_length } || read.size end
Private Instance Methods
http_get(&b)
click to toggle source
Send a request HTTP Get and evaluate the block with the response.
# File lib/pione/location/http-location.rb, line 50 def http_get(&b) http = Net::HTTP.new(@uri.host, @uri.port) req = Net::HTTP::Get.new(@uri.path) res = http.request(req) if res.kind_of?(Net::HTTPSuccess) return b.call(res) else raise NotFound.new(@uri) end end
http_head(&b)
click to toggle source
Send a request HTTP Head and evaluate the block with the response.
# File lib/pione/location/http-location.rb, line 62 def http_head(&b) http = Net::HTTP.new(@uri.host, @uri.port) req = Net::HTTP::Head.new(@uri.path) res = http.request(req) if res.kind_of?(Net::HTTPSuccess) return b.call(res) else raise NotFound(@uri) end end