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 35 def initialize(buffer, options) 36 @options = options 37 @settings = @options.http2_settings 38 @pending = [] 39 @streams = {} 40 @drains = {} 41 @pings = [] 42 @buffer = buffer 43 @handshake_completed = false 44 @wait_for_handshake = @settings.key?(:wait_for_handshake) ? @settings.delete(:wait_for_handshake) : true 45 @max_concurrent_requests = @options.max_concurrent_requests || MAX_CONCURRENT_REQUESTS 46 @max_requests = @options.max_requests 47 init_connection 48 end
Public Instance methods
<<(data)
[show source]
# File lib/httpx/connection/http2.rb 105 def <<(data) 106 @connection << data 107 end
close()
[show source]
# File lib/httpx/connection/http2.rb 89 def close 90 unless @connection.state == :closed 91 @connection.goaway 92 emit(:timeout, @options.timeout[:close_handshake_timeout]) 93 end 94 emit(:close) 95 end
consume()
[show source]
# File lib/httpx/connection/http2.rb 127 def consume 128 @streams.each do |request, stream| 129 next unless request.can_buffer? 130 131 handle(request, stream) 132 end 133 end
empty?()
[show source]
# File lib/httpx/connection/http2.rb 97 def empty? 98 @connection.state == :closed || @streams.empty? 99 end
exhausted?()
[show source]
# File lib/httpx/connection/http2.rb 101 def exhausted? 102 !@max_requests.positive? 103 end
handle_error(ex, request = nil)
[show source]
# File lib/httpx/connection/http2.rb 135 def handle_error(ex, request = nil) 136 if ex.is_a?(OperationTimeoutError) && !@handshake_completed && @connection.state != :closed 137 @connection.goaway(:settings_timeout, "closing due to settings timeout") 138 emit(:close_handshake) 139 settings_ex = SettingsTimeoutError.new(ex.timeout, ex.message) 140 settings_ex.set_backtrace(ex.backtrace) 141 ex = settings_ex 142 end 143 @streams.each_key do |req| 144 next if request && request == req 145 146 emit(:error, req, ex) 147 end 148 while (req = @pending.shift) 149 next if request && request == req 150 151 emit(:error, req, ex) 152 end 153 end
interests()
[show source]
# File lib/httpx/connection/http2.rb 56 def interests 57 if @connection.state == :closed 58 return unless @handshake_completed 59 60 return if @buffer.empty? 61 62 return :w 63 end 64 65 unless @connection.state == :connected && @handshake_completed 66 return @buffer.empty? ? :r : :rw 67 end 68 69 unless @connection.send_buffer.empty? 70 return :rw unless @buffer.empty? 71 72 # waiting for WINDOW_UPDATE frames 73 return :r 74 end 75 76 return :w if !@pending.empty? && can_buffer_more_requests? 77 78 return :w unless @drains.empty? 79 80 if @buffer.empty? 81 return if @streams.empty? && @pings.empty? 82 83 :r 84 else 85 :w 86 end 87 end
ping()
[show source]
# File lib/httpx/connection/http2.rb 155 def ping 156 ping = SecureRandom.gen_random(8) 157 @connection.ping(ping.dup) 158 ensure 159 @pings << ping 160 end
send(request, head = false)
[show source]
# File lib/httpx/connection/http2.rb 109 def send(request, head = false) 110 unless can_buffer_more_requests? 111 head ? @pending.unshift(request) : @pending << request 112 return false 113 end 114 unless (stream = @streams[request]) 115 stream = @connection.new_stream 116 handle_stream(stream, request) 117 @streams[request] = stream 118 @max_requests -= 1 119 end 120 handle(request, stream) 121 true 122 rescue ::HTTP2::Error::StreamLimitExceeded 123 @pending.unshift(request) 124 false 125 end
timeout()
[show source]
# File lib/httpx/connection/http2.rb 50 def timeout 51 return @options.timeout[:operation_timeout] if @handshake_completed 52 53 @options.timeout[:settings_timeout] 54 end
waiting_for_ping?()
[show source]
# File lib/httpx/connection/http2.rb 162 def waiting_for_ping? 163 @pings.any? 164 end