Class: Tor::HTTP
- Inherits:
-
Object
- Object
- Tor::HTTP
- Defined in:
- lib/tor/http.rb
Defined Under Namespace
Classes: TooManyRedirects
Class Attribute Summary collapse
-
.redirects_made ⇒ Object
Returns the value of attribute redirects_made.
Class Method Summary collapse
- .get(uri_or_host, path = nil, port = nil, max_redirects = 3) ⇒ Object
- .post(uri_or_host, post_options = {}, path = nil, port = nil) ⇒ Object
Class Attribute Details
.redirects_made ⇒ Object
Returns the value of attribute redirects_made.
10 11 12 |
# File 'lib/tor/http.rb', line 10 def redirects_made @redirects_made end |
Class Method Details
.get(uri_or_host, path = nil, port = nil, max_redirects = 3) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tor/http.rb', line 13 def self.get(uri_or_host, path = nil, port = nil, max_redirects = 3) res, host = "", nil self.redirects_made = 0 if path host = uri_or_host else host = uri_or_host.host port = uri_or_host.port end start_params = start_parameters(uri_or_host, host, port) start_socks_proxy(start_params) do |http| request = Net::HTTP::Get.new(path || uri_or_host.path) Tor.configuration.headers.each do |header, value| request.delete(header) request.add_field(header, value) end res = http.request(request) res = follow_redirect(res, http, max_redirects) # Follow redirects end res end |
.post(uri_or_host, post_options = {}, path = nil, port = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tor/http.rb', line 39 def self.post(uri_or_host, = {}, path = nil, port = nil) res, host = "", nil if path host = uri_or_host else host = uri_or_host.host port = uri_or_host.port path = uri_or_host.request_uri end start_params = start_parameters(uri_or_host, host, port) start_socks_proxy(start_params) do |http| request = Net::HTTP::Post.new(path) request.set_form_data() Tor.configuration.headers.each do |header, value| request.delete(header) request.add_field(header, value) end res = http.request(request) end res end |