Class: Async::HTTP::URLEndpoint
- Inherits:
-
IO::Endpoint
- Object
- IO::Endpoint
- Async::HTTP::URLEndpoint
- Defined in:
- lib/async/http/url_endpoint.rb
Constant Summary collapse
- DEFAULT_ALPH_PROTOCOLS =
['h2', 'http/1.1'].freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #address ⇒ Object
- #bind(*args, &block) ⇒ Object
- #connect(*args, &block) ⇒ Object
- #default_port ⇒ Object
- #each ⇒ Object
- #endpoint ⇒ Object
- #hostname ⇒ Object
-
#initialize(url, endpoint = nil, **options) ⇒ URLEndpoint
constructor
A new instance of URLEndpoint.
- #port ⇒ Object
- #protocol ⇒ Object
- #secure? ⇒ Boolean
- #ssl_context ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(url, endpoint = nil, **options) ⇒ URLEndpoint
Returns a new instance of URLEndpoint.
33 34 35 36 37 38 |
# File 'lib/async/http/url_endpoint.rb', line 33 def initialize(url, endpoint = nil, **) super(**) @url = url @endpoint = endpoint end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
45 46 47 |
# File 'lib/async/http/url_endpoint.rb', line 45 def @options end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
44 45 46 |
# File 'lib/async/http/url_endpoint.rb', line 44 def url @url end |
Class Method Details
.parse(string, **options) ⇒ Object
29 30 31 |
# File 'lib/async/http/url_endpoint.rb', line 29 def self.parse(string, **) self.new(URI.parse(string), **) end |
Instance Method Details
#address ⇒ Object
47 48 49 |
# File 'lib/async/http/url_endpoint.rb', line 47 def address endpoint.address end |
#bind(*args, &block) ⇒ Object
98 99 100 |
# File 'lib/async/http/url_endpoint.rb', line 98 def bind(*args, &block) endpoint.bind(*args, &block) end |
#connect(*args, &block) ⇒ Object
102 103 104 |
# File 'lib/async/http/url_endpoint.rb', line 102 def connect(*args, &block) endpoint.connect(*args, &block) end |
#default_port ⇒ Object
63 64 65 |
# File 'lib/async/http/url_endpoint.rb', line 63 def default_port secure? ? 443 : 80 end |
#each ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/async/http/url_endpoint.rb', line 106 def each return to_enum unless block_given? self.endpoint.each do |endpoint| yield self.class.new(@url, endpoint, @options) end end |
#endpoint ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/async/http/url_endpoint.rb', line 82 def endpoint unless @endpoint @endpoint = Async::IO::Endpoint.tcp(hostname, port) if secure? # Wrap it in SSL: @endpoint = Async::IO::SecureEndpoint.new(@endpoint, ssl_context: ssl_context, hostname: self.hostname ) end end return @endpoint end |
#hostname ⇒ Object
71 72 73 |
# File 'lib/async/http/url_endpoint.rb', line 71 def hostname @options.fetch(:hostname, @url.hostname) end |
#port ⇒ Object
67 68 69 |
# File 'lib/async/http/url_endpoint.rb', line 67 def port @url.port || default_port end |
#protocol ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/async/http/url_endpoint.rb', line 55 def protocol if secure? Protocol::HTTPS else Protocol::HTTP1 end end |
#secure? ⇒ Boolean
51 52 53 |
# File 'lib/async/http/url_endpoint.rb', line 51 def secure? ['https', 'wss'].include?(@url.scheme) end |
#ssl_context ⇒ Object
75 76 77 78 79 80 |
# File 'lib/async/http/url_endpoint.rb', line 75 def ssl_context @options[:ssl_context] || ::OpenSSL::SSL::SSLContext.new.tap do |context| context.alpn_protocols = @options.fetch(:alpn_protocols, DEFAULT_ALPH_PROTOCOLS) context.set_params end end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/async/http/url_endpoint.rb', line 40 def to_s "\#<#{self.class} #{@url} #{@options.inspect}>" end |