Class: HTTPX::Connection::HTTP2

Inherits:
Object
  • Object
show all
Includes:
HTTPX::Callbacks, Loggable
Defined in:
lib/httpx/connection/http2.rb

Direct Known Subclasses

Plugins::H2C::H2CParser

Defined Under Namespace

Modules: HTTP2Extensions

Constant Summary collapse

Error =
Class.new(Error) do
  def initialize(id, code)
    super("stream #{id} closed with error: #{code}")
  end
end

Constants included from Loggable

Loggable::COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#log, #log_exception

Methods included from HTTPX::Callbacks

#emit, #on, #once

Constructor Details

#initialize(buffer, options) ⇒ HTTP2

Returns a new instance of HTTP2.



35
36
37
38
39
40
41
42
43
44
# File 'lib/httpx/connection/http2.rb', line 35

def initialize(buffer, options)
  @options = Options.new(options)
  @max_concurrent_requests = @options.max_concurrent_requests
  @pending = []
  @streams = {}
  @drains  = {}
  @buffer = buffer
  @handshake_completed = false
  init_connection
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object (private)



285
286
287
288
289
290
291
# File 'lib/httpx/connection/http2.rb', line 285

def method_missing(meth, *args, &blk)
  if @connection.respond_to?(meth)
    @connection.__send__(meth, *args, &blk)
  else
    super
  end
end

Instance Attribute Details

#pendingObject (readonly)

Returns the value of attribute pending.



33
34
35
# File 'lib/httpx/connection/http2.rb', line 33

def pending
  @pending
end

#streamsObject (readonly)

Returns the value of attribute streams.



33
34
35
# File 'lib/httpx/connection/http2.rb', line 33

def streams
  @streams
end

Instance Method Details

#<<(data) ⇒ Object



54
55
56
# File 'lib/httpx/connection/http2.rb', line 54

def <<(data)
  @connection << data
end

#closeObject



46
47
48
# File 'lib/httpx/connection/http2.rb', line 46

def close
  @connection.goaway
end

#consumeObject



82
83
84
85
86
# File 'lib/httpx/connection/http2.rb', line 82

def consume
  @streams.each do |request, stream|
    handle(request, stream)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/httpx/connection/http2.rb', line 50

def empty?
  @connection.state == :closed || @streams.empty?
end

#handle_error(ex) ⇒ Object



88
89
90
91
92
# File 'lib/httpx/connection/http2.rb', line 88

def handle_error(ex)
  @streams.each_key do |request|
    emit(:error, request, ex)
  end
end

#reenqueue!Object



73
74
75
76
77
78
79
80
# File 'lib/httpx/connection/http2.rb', line 73

def reenqueue!
  requests = @streams.keys
  @streams.clear
  init_connection
  requests.each do |request|
    send(request)
  end
end

#send(request) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/httpx/connection/http2.rb', line 58

def send(request, **)
  if !@handshake_completed ||
     @connection.active_stream_count >= @max_concurrent_requests
    @pending << request
    return
  end
  unless (stream = @streams[request])
    stream = @connection.new_stream
    handle_stream(stream, request)
    @streams[request] = stream
  end
  handle(request, stream)
  true
end