Sha256: 2c900b17ecc9f59852584d9f715c6185e50eb14811f9b5a3f26c5bb598e1993c
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 KB
Contents
# `Rawler::Request` contains some abstraction for making web requests, like automatically adding ssl and basic auth. module Rawler class Request class << self def get(url) perform_request(:get, url) end def head(url) perform_request(:head, url) end private def perform_request(method, url) uri = URI.parse(url) # Use http_proxy if set proxy = URI.parse(ENV['http_proxy']) if ENV['http_proxy'] rescue nil if proxy http = Net::HTTP::Proxy(proxy.host, proxy.port).new(uri.host, uri.port) else http = Net::HTTP.new(uri.host, uri.port) end http.use_ssl = (uri.scheme == 'https') http.verify_mode = OpenSSL::SSL::VERIFY_NONE path = (uri.path.size == 0) ? "/" : uri.path request = Net::HTTP::Get.new(path) request.basic_auth(Rawler.username, Rawler.password) http.request(request) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rawler-0.1.3 | lib/rawler/request.rb |