class UV::HttpEndpoint::Connection
Attributes
reason[RW]
request[RW]
Public Class Methods
new(host, port, tls, proxy, client)
click to toggle source
Calls superclass method
UV::OutboundConnection::new
# File lib/uv-rays/http_endpoint.rb, line 57 def initialize(host, port, tls, proxy, client) @target_host = host @client = client @request = nil if proxy super(proxy[:host], proxy[:port]) if tls @negotiating = true @proxy = proxy @connect_host = host @connect_port = port end else super(host, port) start_tls if tls end end
Public Instance Methods
close_connection(request = nil)
click to toggle source
Calls superclass method
UV::TcpConnection#close_connection
# File lib/uv-rays/http_endpoint.rb, line 127 def close_connection(request = nil) if request.is_a? Http::Request @request = request super(:after_writing) else super(request) end end
connect_send_handshake(target_host, target_port, proxy)
click to toggle source
# File lib/uv-rays/http_endpoint.rb, line 81 def connect_send_handshake(target_host, target_port, proxy) header = String.new("CONNECT #{target_host}:#{target_port} HTTP/1.0\r\n") if proxy[:username] || proxy[:password] encoded_credentials = Base64.strict_encode64([proxy[:username], proxy[:password]].join(":")) header << "Proxy-Authorization: Basic #{encoded_credentials}\r\n" end header << "\r\n" write(header) end
on_close()
click to toggle source
# File lib/uv-rays/http_endpoint.rb, line 119 def on_close @client.connection_closed(@request, @reason) ensure @request = nil @client = nil @reason = nil end
on_connect(transport)
click to toggle source
# File lib/uv-rays/http_endpoint.rb, line 111 def on_connect(transport) if @negotiating connect_send_handshake(@connect_host, @connect_port, @proxy) else @client.connection_ready end end
on_read(data, *args)
click to toggle source
# File lib/uv-rays/http_endpoint.rb, line 93 def on_read(data, *args) if @negotiating @negotiating = false if data =~ %r{\AHTTP/1\.[01] 200 .*\r\n\r\n}m start_tls @client.connection_ready else @reason = "Unexpected response from proxy: #{data}" close_connection end else @client.data_received(data) end end
post_init(*args)
click to toggle source
# File lib/uv-rays/http_endpoint.rb, line 108 def post_init(*args) end
start_tls()
click to toggle source
# File lib/uv-rays/http_endpoint.rb, line 76 def start_tls opts = {host_name: @target_host}.merge(@client.tls_options) use_tls(opts) end