Module: HTTPX::Plugins::H2C::ConnectionMethods

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

Instance Method Summary collapse

Instance Method Details

#initializeObject



48
49
50
51
# File 'lib/httpx/plugins/h2c.rb', line 48

def initialize(*)
  super
  @h2c_handshake = false
end

#send(request) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/httpx/plugins/h2c.rb', line 53

def send(request)
  return super if @h2c_handshake

  return super unless VALID_H2C_VERBS.include?(request.verb) && request.scheme == "http"

  return super if @upgrade_protocol == "h2c"

  @h2c_handshake = true

  # build upgrade request
  request.headers.add("connection", "upgrade")
  request.headers.add("connection", "http2-settings")
  request.headers["upgrade"] = "h2c"
  request.headers["http2-settings"] = ::HTTP2::Client.settings_header(request.options.http2_settings)

  super
end

#upgrade_to_h2c(request, response) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/httpx/plugins/h2c.rb', line 71

def upgrade_to_h2c(request, response)
  prev_parser = @parser

  if prev_parser
    prev_parser.reset
    @inflight -= prev_parser.requests.size
  end

  @parser = H2CParser.new(@write_buffer, @options)
  set_parser_callbacks(@parser)
  @inflight += 1
  @parser.upgrade(request, response)
  @upgrade_protocol = "h2c"

  prev_parser.requests.each do |req|
    req.transition(:idle)
    send(req)
  end
end