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