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