Public Instance methods
request(*args, **options)
[show source]
# File lib/httpx/plugins/proxy/ssh.rb 24 def request(*args, **options) 25 raise ArgumentError, "must perform at least one request" if args.empty? 26 27 requests = args.first.is_a?(Request) ? args : build_requests(*args, options) 28 29 request = requests.first or return super 30 31 request_options = request.options 32 33 return super unless request_options.proxy 34 35 ssh_options = request_options.proxy 36 ssh_uris = ssh_options.delete(:uri) 37 ssh_uri = URI.parse(ssh_uris.shift) 38 39 return super unless ssh_uri.scheme == "ssh" 40 41 ssh_username = ssh_options.delete(:username) 42 ssh_options[:port] ||= ssh_uri.port || 22 43 if request_options.debug 44 ssh_options[:verbose] = request_options.debug_level == 2 ? :debug : :info 45 end 46 47 request_uri = URI(requests.first.uri) 48 @_gateway = Net::SSH::Gateway.new(ssh_uri.host, ssh_username, ssh_options) 49 begin 50 @_gateway.open(request_uri.host, request_uri.port) do |local_port| 51 io = build_gateway_socket(local_port, request_uri, request_options) 52 super(*args, **options.merge(io: io)) 53 end 54 ensure 55 @_gateway.shutdown! 56 end 57 end