Module: HTTPX::AltSvc::ConnectionMixin
- Defined in:
- lib/httpx/altsvc.rb,
sig/altsvc.rbs
Overview
makes connections able to accept requests destined to primary service.
Constant Summary collapse
- H2_ALTSVC_SCHEMES =
%w[https h2].freeze
- ALTSVC_IGNORE_IVARS =
%i[@ssl].freeze
Instance Method Summary collapse
- #altsvc_match?(uri, other_uri) ⇒ Boolean
- #match?(uri, options) ⇒ Boolean
- #match_altsvc_options?(uri, options) ⇒ Boolean
-
#match_altsvcs?(uri) ⇒ Boolean
checks if this is connection is an alternative service of
uri. - #send(request) ⇒ void
Instance Method Details
#altsvc_match?(uri, other_uri) ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/httpx/altsvc.rb', line 47 def altsvc_match?(uri, other_uri) other_uri = URI(other_uri) #: http_uri uri.origin == other_uri.origin || begin case uri.scheme when "h2" H2_ALTSVC_SCHEMES.include?(other_uri.scheme) && uri.host == other_uri.host && uri.port == other_uri.port else false end end end |
#match?(uri, options) ⇒ Boolean
21 22 23 24 25 |
# File 'lib/httpx/altsvc.rb', line 21 def match?(uri, ) return false if !used? && (@state == :closing || @state == :closed) match_altsvcs?(uri) && (uri, ) end |
#match_altsvc_options?(uri, options) ⇒ Boolean
39 40 41 42 43 44 45 |
# File 'lib/httpx/altsvc.rb', line 39 def (uri, ) return @options.() unless @options.ssl.all? do |k, v| v == (k == :hostname ? uri.host : .ssl[k]) end @options.(, ALTSVC_IGNORE_IVARS) end |
#match_altsvcs?(uri) ⇒ Boolean
checks if this is connection is an alternative service of
uri
31 32 33 34 35 36 37 |
# File 'lib/httpx/altsvc.rb', line 31 def match_altsvcs?(uri) @origins.any? { |origin| altsvc_match?(uri, origin) } || AltSvc.cached_altsvc(@origin).any? do |altsvc| origin = altsvc["origin"] altsvc_match?(origin, uri.origin) end end |
#send(request) ⇒ void
This method returns an undefined value.
15 16 17 18 19 |
# File 'lib/httpx/altsvc.rb', line 15 def send(request) request.headers["alt-used"] = @origin. if @parser && !@write_buffer.full? && match_altsvcs?(request.uri) super end |