Sha256: 816f3b9cc4034edeae7a936daae46c70b144bd69ef60dc1fa46ee38ec940bd2e
Contents?: true
Size: 1.5 KB
Versions: 3
Compression:
Stored size: 1.5 KB
Contents
module Yawast module Shared class Http def self.setup(proxy, cookie) if proxy != nil && proxy.include?(':') @proxy_host, @proxy_port = proxy.split(':') @proxy = true puts "Using Proxy: #{proxy}" else @proxy = false end @cookie = cookie puts "Using Cookie: #{@cookie}" if @cookie != nil end def self.head(uri) req = get_http(uri) req.use_ssl = uri.scheme == 'https' req.head(uri.path, get_headers) end def self.get(uri) body = '' begin req = get_http(uri) req.use_ssl = uri.scheme == 'https' res = req.request_get(uri.path, get_headers) body = res.read_body rescue #do nothing for now end body end def self.get_status_code(uri) req = get_http(uri) req.use_ssl = uri.scheme == 'https' res = req.head(uri.path, get_headers) res.code end def self.get_http(uri) if @proxy req = Net::HTTP.new(uri.host, uri.port, @proxy_host, @proxy_port) else req = Net::HTTP.new(uri.host, uri.port) end req end # noinspection RubyStringKeysInHashInspection def self.get_headers if @cookie == nil headers = { 'User-Agent' => HTTP_UA } else headers = { 'User-Agent' => HTTP_UA, 'Cookie' => @cookie } end headers end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
yawast-0.5.0.beta1 | lib/shared/http.rb |
yawast-0.4.0 | lib/shared/http.rb |
yawast-0.4.0.beta5 | lib/shared/http.rb |