Class: Tor::HTTP
- Inherits:
-
Object
- Object
- Tor::HTTP
- Defined in:
- lib/tor/http.rb
Defined Under Namespace
Classes: TooManyRedirects
Constant Summary collapse
- REDIRECT_LIMIT =
3
Class Attribute Summary collapse
-
.redirects_count ⇒ Object
Returns the value of attribute redirects_count.
Class Method Summary collapse
- .get(uri_or_host, path = nil, port = nil) ⇒ Object
- .post(uri_or_host, post_options = {}, path = nil, port = nil) ⇒ Object
Class Attribute Details
.redirects_count ⇒ Object
Returns the value of attribute redirects_count.
11 12 13 |
# File 'lib/tor/http.rb', line 11 def redirects_count @redirects_count end |
Class Method Details
.get(uri_or_host, path = nil, port = nil) ⇒ Object
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 14 def self.get(uri_or_host, path = nil, port = nil) res, host = "", nil self.redirects_count = 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) # 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 |