Sha256: 2b90f2bcba7758d4e2d44c9520d0bfe55986f87bb582218786bc4bb230aea4a4
Contents?: true
Size: 1.06 KB
Versions: 2
Compression:
Stored size: 1.06 KB
Contents
require 'net/http' module Anemone class HTTP < Net::HTTP # Maximum number of redirects to follow on each get_response REDIRECTION_LIMIT = 5 # # Retrieve an HTTP response for *url*, following redirects. # Returns the response object, response code, and final URI location. # def self.get(url) response = get_response(url) code = Integer(response.code) loc = url limit = REDIRECTION_LIMIT while response.is_a?(Net::HTTPRedirection) and limit > 0 loc = URI(response['location']) loc = url.merge(loc) if loc.relative? response = get_response(loc) limit -= 1 end return response, code, loc end # # Get an HTTPResponse for *url*, sending the appropriate User-Agent string # def self.get_response(url) full_path = url.query.nil? ? url.path : "#{url.path}?#{url.query}" Net::HTTP.start(url.host, url.port) do |http| return http.get(full_path, {'User-Agent' => Anemone::USER_AGENT }) end end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
jeremyf-anemone-0.1.3 | lib/anemone/http.rb |
anemone-0.1.1 | lib/anemone/http.rb |