Class: Tor::HTTP
- Inherits:
-
Object
- Object
- Tor::HTTP
- Defined in:
- lib/tor/http.rb
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 Method Details
.get(uri_or_host, path = nil, port = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tor/http.rb', line 8 def self.get(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 end Net::HTTP.SOCKSProxy(Tor.configuration.ip, Tor.configuration.port).start(host, port) 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); end res end |
.post(uri_or_host, post_options = {}, path = nil, port = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tor/http.rb', line 29 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 Net::HTTP.SOCKSProxy(Tor.configuration.ip, Tor.configuration.port).start(host, port) 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 |