Methods
Public Class
Public Instance
Classes and Modules
Constants
| MAX_CONCURRENT_REQUESTS | = | ::HTTP2::DEFAULT_MAX_CONCURRENT_STREAMS |
Public Instance Aliases
| reset | -> | init_connection |
Public Class methods
new(buffer, options)
[show source]
# File lib/httpx/connection/http2.rb 33 def initialize(buffer, options) 34 @options = options 35 @settings = @options.http2_settings 36 @pending = [] 37 @streams = {} 38 @drains = {} 39 @pings = [] 40 @buffer = buffer 41 @handshake_completed = false 42 @wait_for_handshake = @settings.key?(:wait_for_handshake) ? @settings.delete(:wait_for_handshake) : true 43 @max_concurrent_requests = @options.max_concurrent_requests || MAX_CONCURRENT_REQUESTS 44 @max_requests = @options.max_requests 45 init_connection 46 end
Public Instance methods
<<(data)
[show source]
# File lib/httpx/connection/http2.rb 111 def <<(data) 112 @connection << data 113 end
close()
[show source]
# File lib/httpx/connection/http2.rb 95 def close 96 unless @connection.state == :closed 97 @connection.goaway 98 emit(:timeout, @options.timeout[:close_handshake_timeout]) 99 end 100 emit(:close) 101 end
consume()
[show source]
# File lib/httpx/connection/http2.rb 135 def consume 136 @streams.each do |request, stream| 137 next unless request.can_buffer? 138 139 handle(request, stream) 140 end 141 end
empty?()
[show source]
# File lib/httpx/connection/http2.rb 103 def empty? 104 @connection.state == :closed || @streams.empty? 105 end
exhausted?()
[show source]
# File lib/httpx/connection/http2.rb 107 def exhausted? 108 !@max_requests.positive? 109 end
handle_error(ex, request = nil)
[show source]
# File lib/httpx/connection/http2.rb 143 def handle_error(ex, request = nil) 144 if ex.is_a?(OperationTimeoutError) && !@handshake_completed && @connection.state != :closed 145 @connection.goaway(:settings_timeout, "closing due to settings timeout") 146 emit(:close_handshake) 147 settings_ex = SettingsTimeoutError.new(ex.timeout, ex.message) 148 settings_ex.set_backtrace(ex.backtrace) 149 ex = settings_ex 150 end 151 while (req, _ = @streams.shift) 152 next if request && request == req 153 154 emit(:error, req, ex) 155 end 156 while (req = @pending.shift) 157 next if request && request == req 158 159 emit(:error, req, ex) 160 end 161 end
interests()
[show source]
# File lib/httpx/connection/http2.rb 54 def interests 55 if @connection.state == :closed 56 return unless @handshake_completed 57 58 return if @buffer.empty? 59 60 # HTTP/2 GOAWAY frame buffered. 61 return :w 62 end 63 64 unless @connection.state == :connected && @handshake_completed 65 # HTTP/2 in intermediate state or still completing initialization- 66 return @buffer.empty? ? :r : :rw 67 end 68 69 unless @connection.send_buffer.empty? 70 # HTTP/2 connection is buffering data chunks and failing to emit DATA frames, 71 # most likely because the flow control window is exhausted. 72 return :rw unless @buffer.empty? 73 74 # waiting for WINDOW_UPDATE frames 75 return :r 76 end 77 78 # there are pending bufferable requests 79 return :w if !@pending.empty? && can_buffer_more_requests? 80 81 # there are pending frames from the last run 82 return :w unless @drains.empty? 83 84 if @buffer.empty? 85 # skip if no more requests or pings to process 86 return if @streams.empty? && @pings.empty? 87 88 :r 89 else 90 # buffered frames 91 :w 92 end 93 end
ping()
[show source]
# File lib/httpx/connection/http2.rb 163 def ping 164 ping = SecureRandom.gen_random(8) 165 @connection.ping(ping.dup) 166 ensure 167 @pings << ping 168 end
send(request, head = false)
[show source]
# File lib/httpx/connection/http2.rb 115 def send(request, head = false) 116 unless can_buffer_more_requests? 117 head ? @pending.unshift(request) : @pending << request 118 return false 119 end 120 unless (stream = @streams[request]) 121 stream = @connection.new_stream(**request.http2_stream_options) 122 handle_stream(stream, request) 123 @streams[request] = stream 124 @max_requests -= 1 125 end 126 handle(request, stream) 127 true 128 rescue ::HTTP2::Error::StreamLimitExceeded 129 @pending.unshift(request) 130 false 131 rescue StandardError => e 132 emit(:error, request, e) 133 end
timeout()
[show source]
# File lib/httpx/connection/http2.rb 48 def timeout 49 return @options.timeout[:operation_timeout] if @handshake_completed 50 51 @options.timeout[:settings_timeout] 52 end
waiting_for_ping?()
[show source]
# File lib/httpx/connection/http2.rb 170 def waiting_for_ping? 171 @pings.any? 172 end