Class: ProxyFetcher::HTTPClient
- Inherits:
-
Object
- Object
- ProxyFetcher::HTTPClient
- Defined in:
- lib/proxy_fetcher/utils/http_fetcher.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(url) ⇒ HTTPClient
constructor
A new instance of HTTPClient.
Constructor Details
#initialize(url) ⇒ HTTPClient
Returns a new instance of HTTPClient.
5 6 7 8 9 |
# File 'lib/proxy_fetcher/utils/http_fetcher.rb', line 5 def initialize(url) @uri = URI.parse(url) @http = Net::HTTP.new(@uri.host, @uri.port) @http.use_ssl = true if @uri.scheme.downcase == 'https' end |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
3 4 5 |
# File 'lib/proxy_fetcher/utils/http_fetcher.rb', line 3 def http @http end |
Class Method Details
.fetch(url) ⇒ Object
19 20 21 |
# File 'lib/proxy_fetcher/utils/http_fetcher.rb', line 19 def fetch(url) new(url).fetch end |
Instance Method Details
#fetch ⇒ Object
11 12 13 14 15 16 |
# File 'lib/proxy_fetcher/utils/http_fetcher.rb', line 11 def fetch request = Net::HTTP::Get.new(@uri.to_s) request['Connection'] = 'keep-alive' response = @http.request(request) response.body end |