Class: HTTPX::Channel::HTTP2

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

Constant Summary

Constants included from Loggable

Loggable::COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#log

Methods included from HTTPX::Callbacks

#emit, #on, #once

Constructor Details

#initialize(buffer, options) ⇒ HTTP2

Returns a new instance of HTTP2.



12
13
14
15
16
17
18
19
20
# File 'lib/httpx/channel/http2.rb', line 12

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



222
223
224
225
226
227
228
# File 'lib/httpx/channel/http2.rb', line 222

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.



10
11
12
# File 'lib/httpx/channel/http2.rb', line 10

def pending
  @pending
end

#streamsObject (readonly)

Returns the value of attribute streams.



10
11
12
# File 'lib/httpx/channel/http2.rb', line 10

def streams
  @streams
end

Instance Method Details

#<<(data) ⇒ Object



30
31
32
# File 'lib/httpx/channel/http2.rb', line 30

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

#closeObject



22
23
24
# File 'lib/httpx/channel/http2.rb', line 22

def close
  @connection.goaway
end

#consumeObject



56
57
58
59
60
# File 'lib/httpx/channel/http2.rb', line 56

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

#empty?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/httpx/channel/http2.rb', line 26

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

#handle_error(ex) ⇒ Object



62
63
64
65
66
# File 'lib/httpx/channel/http2.rb', line 62

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

#reenqueue!Object



47
48
49
50
51
52
53
54
# File 'lib/httpx/channel/http2.rb', line 47

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

#send(request) ⇒ Object



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

def send(request, **)
  if @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)
end