class HTTPX::Connection::HTTP2

  1. lib/httpx/connection/http2.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. <<
  2. close
  3. consume
  4. empty?
  5. exhausted?
  6. handle_error
  7. pending
  8. reset
  9. send
  10. streams

Included modules

  1. Callbacks
  2. Loggable

Constants

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

Attributes

pending [R]
streams [R]

Public Class methods

new (buffer, options)
[show source]
   # File lib/httpx/connection/http2.rb
21 def initialize(buffer, options)
22   @options = Options.new(options)
23   @max_concurrent_requests = @options.max_concurrent_requests || MAX_CONCURRENT_REQUESTS
24   @max_requests = @options.max_requests || 0
25   @pending = []
26   @streams = {}
27   @drains  = {}
28   @buffer = buffer
29   @handshake_completed = false
30   init_connection
31 end

Public Instance methods

<< (data)
[show source]
   # File lib/httpx/connection/http2.rb
49 def <<(data)
50   @connection << data
51 end
close ()
[show source]
   # File lib/httpx/connection/http2.rb
37 def close
38   @connection.goaway unless @connection.state == :closed
39 end
consume ()
[show source]
   # File lib/httpx/connection/http2.rb
73 def consume
74   @streams.each do |request, stream|
75     handle(request, stream)
76   end
77 end
empty? ()
[show source]
   # File lib/httpx/connection/http2.rb
41 def empty?
42   @connection.state == :closed || @streams.empty?
43 end
exhausted? ()
[show source]
   # File lib/httpx/connection/http2.rb
45 def exhausted?
46   @connection.active_stream_count >= @max_requests
47 end
handle_error (ex)
[show source]
   # File lib/httpx/connection/http2.rb
79 def handle_error(ex)
80   @streams.each_key do |request|
81     emit(:error, request, ex)
82   end
83   @pending.each do |request|
84     emit(:error, request, ex)
85   end
86 end
reset ()
[show source]
   # File lib/httpx/connection/http2.rb
33 def reset
34   init_connection
35 end
send (request)
[show source]
   # File lib/httpx/connection/http2.rb
53 def send(request)
54   if !@handshake_completed ||
55      @streams.size >= @max_concurrent_requests ||
56      @streams.size >= @max_requests
57     @pending << request
58     return
59   end
60   unless (stream = @streams[request])
61     stream = @connection.new_stream
62     handle_stream(stream, request)
63     @streams[request] = stream
64     @max_requests -= 1
65   end
66   handle(request, stream)
67   true
68 rescue HTTP2Next::Error::StreamLimitExceeded
69   @pending.unshift(request)
70   emit(:exhausted)
71 end