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 =

Returns:

  • (Array[String])
%w[https h2].freeze
ALTSVC_IGNORE_IVARS =

Returns:

  • (Array[Symbol])
%i[@ssl].freeze

Instance Method Summary collapse

Instance Method Details

#altsvc_match?(uri, other_uri) ⇒ Boolean

Parameters:

  • uri (http_uri)
  • other_uri (uri)

Returns:

  • (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

Parameters:

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/httpx/altsvc.rb', line 21

def match?(uri, options)
  return false if !used? && (@state == :closing || @state == :closed)

  match_altsvcs?(uri) && match_altsvc_options?(uri, options)
end

#match_altsvc_options?(uri, options) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/httpx/altsvc.rb', line 39

def match_altsvc_options?(uri, options)
  return @options.connection_options_match?(options) unless @options.ssl.all? do |k, v|
    v == (k == :hostname ? uri.host : options.ssl[k])
  end

  @options.connection_options_match?(options, ALTSVC_IGNORE_IVARS)
end

#match_altsvcs?(uri) ⇒ Boolean

checks if this is connection is an alternative service of uri

Parameters:

  • uri (http_uri)

Returns:

  • (Boolean)


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.

Parameters:



15
16
17
18
19
# File 'lib/httpx/altsvc.rb', line 15

def send(request)
  request.headers["alt-used"] = @origin.authority if @parser && !@write_buffer.full? && match_altsvcs?(request.uri)

  super
end