Class: Medusa::HTTP
- Inherits:
-
Object
- Object
- Medusa::HTTP
- Defined in:
- lib/medusa/http.rb
Constant Summary collapse
- REDIRECT_LIMIT =
Maximum number of redirects to follow on each get_response
5
- RETRY_LIMIT =
6
Instance Attribute Summary collapse
-
#cookie_store ⇒ Object
readonly
CookieStore for this HTTP client.
Instance Method Summary collapse
-
#accept_cookies? ⇒ Boolean
Does this HTTP client accept cookies from the server?.
-
#fetch_page(url, referer = nil, depth = nil) ⇒ Object
Fetch a single Page from the response of an HTTP request to url.
-
#fetch_pages(url, referer = nil, depth = nil) ⇒ Object
Create new Pages from the response of an HTTP request to url, including redirects.
-
#http_basic_authentication ⇒ Object
The http authentication options as in www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/OpenURI/OpenRead.html userinfo is deprecated [RFC3986].
-
#initialize(opts = {}) ⇒ HTTP
constructor
A new instance of HTTP.
-
#proxy ⇒ Object
The proxy options as in www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/OpenURI/OpenRead.html.
-
#proxy_host ⇒ Object
The proxy address string.
-
#proxy_http_basic_authentication ⇒ Object
The proxy authentication options as in www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/OpenURI/OpenRead.html.
-
#proxy_port ⇒ Object
The proxy port.
-
#read_timeout ⇒ Object
HTTP read timeout in seconds.
-
#redirect_limit ⇒ Object
The maximum number of redirects to follow.
-
#user_agent ⇒ Object
The user-agent string which will be sent with each request, or nil if no such option is set.
Constructor Details
#initialize(opts = {}) ⇒ HTTP
Returns a new instance of HTTP.
14 15 16 17 |
# File 'lib/medusa/http.rb', line 14 def initialize(opts = {}) @opts = opts @cookie_store = CookieStore.new(@opts[:cookies]) end |
Instance Attribute Details
#cookie_store ⇒ Object (readonly)
CookieStore for this HTTP client
12 13 14 |
# File 'lib/medusa/http.rb', line 12 def @cookie_store end |
Instance Method Details
#accept_cookies? ⇒ Boolean
Does this HTTP client accept cookies from the server?
69 70 71 |
# File 'lib/medusa/http.rb', line 69 def @opts[:accept_cookies] end |
#fetch_page(url, referer = nil, depth = nil) ⇒ Object
Fetch a single Page from the response of an HTTP request to url. Just gets the final destination page.
23 24 25 |
# File 'lib/medusa/http.rb', line 23 def fetch_page(url, referer = nil, depth = nil) fetch_pages(url, referer, depth).last end |
#fetch_pages(url, referer = nil, depth = nil) ⇒ Object
Create new Pages from the response of an HTTP request to url, including redirects
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/medusa/http.rb', line 31 def fetch_pages(url, referer = nil, depth = nil) pages = [] begin url = URI(url) unless url.is_a?(URI) get(url, referer) do |response, headers, code, location, redirect_to, response_time| pages << Page.new(location, :body => response, :headers => headers, :code => code, :referer => referer, :depth => depth, :redirect_to => redirect_to, :response_time => response_time) end return pages rescue StandardError => e return pages << Page.new(url, error: e) end end |
#http_basic_authentication ⇒ Object
The http authentication options as in www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/OpenURI/OpenRead.html userinfo is deprecated [RFC3986]
77 78 79 |
# File 'lib/medusa/http.rb', line 77 def http_basic_authentication @opts[:http_basic_authentication] end |
#proxy ⇒ Object
The proxy options as in www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/OpenURI/OpenRead.html
91 92 93 |
# File 'lib/medusa/http.rb', line 91 def proxy @opts[:proxy] end |
#proxy_host ⇒ Object
The proxy address string
98 99 100 |
# File 'lib/medusa/http.rb', line 98 def proxy_host @opts[:proxy_host] end |
#proxy_http_basic_authentication ⇒ Object
The proxy authentication options as in www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/OpenURI/OpenRead.html
84 85 86 |
# File 'lib/medusa/http.rb', line 84 def proxy_http_basic_authentication @opts[:proxy_http_basic_authentication] end |
#proxy_port ⇒ Object
The proxy port
105 106 107 |
# File 'lib/medusa/http.rb', line 105 def proxy_port @opts[:proxy_port] end |
#read_timeout ⇒ Object
HTTP read timeout in seconds
112 113 114 |
# File 'lib/medusa/http.rb', line 112 def read_timeout @opts[:read_timeout] end |
#redirect_limit ⇒ Object
The maximum number of redirects to follow
54 55 56 |
# File 'lib/medusa/http.rb', line 54 def redirect_limit @opts[:redirect_limit] || REDIRECT_LIMIT end |
#user_agent ⇒ Object
The user-agent string which will be sent with each request, or nil if no such option is set
62 63 64 |
# File 'lib/medusa/http.rb', line 62 def user_agent @opts[:user_agent] end |