Module: HTTPX::Plugins::H2C::InstanceMethods

Defined in:
lib/httpx/plugins/h2c.rb

Instance Method Summary collapse

Instance Method Details

#request(*args, **options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/httpx/plugins/h2c.rb', line 17

def request(*args, **options)
  h2c_options = options.merge(fallback_protocol: "h2c")

  requests = build_requests(*args, h2c_options)

  upgrade_request = requests.first
  return super unless valid_h2c_upgrade_request?(upgrade_request)

  upgrade_request.headers.add("connection", "upgrade")
  upgrade_request.headers.add("connection", "http2-settings")
  upgrade_request.headers["upgrade"] = "h2c"
  upgrade_request.headers["http2-settings"] = HTTP2::Client.settings_header(upgrade_request.options.http2_settings)
  wrap { send_requests(*upgrade_request, h2c_options).first }

  responses = send_requests(*requests, h2c_options)

  return responses.first if responses.size == 1

  responses
end