Sha256: a6a4a03c70d3facf179a694835cda6a633743c064e1331ab86acdabeaae4bf36

Contents?: true

Size: 835 Bytes

Versions: 5

Compression:

Stored size: 835 Bytes

Contents

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)

        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

5 entries across 5 versions & 1 rubygems

Version Path
rawler-0.1.8 lib/rawler/request.rb
rawler-0.1.7 lib/rawler/request.rb
rawler-0.1.6 lib/rawler/request.rb
rawler-0.1.5 lib/rawler/request.rb
rawler-0.1.4 lib/rawler/request.rb