Methods
Public Class
Public Instance
Attributes
| connection | [R] |
TODO: would be nice to get rid of this |
| hedge_request | [R] |
Public Class methods
new(*)
[show source]
# File lib/httpx/plugins/hedging.rb 139 def initialize(*) 140 super 141 @is_hedge_request = false 142 end
Public Instance methods
emit_response(response)
[show source]
# File lib/httpx/plugins/hedging.rb 168 def emit_response(response) 169 hedge_request = @hedge_request 170 171 return super unless hedge_request 172 173 return super unless hedge_request && 174 ( 175 hedge_request.response.nil? || 176 !hedge_request.response.finished? 177 ) 178 179 # if this response is for a hedge request, and the main request 180 # didn't complete yet, then we replace it. 181 182 super.tap do 183 hedge_request.response = response 184 185 # should cancel any pending HTTP/2 stream; there's no way to 186 # cancel an HTTP/1 request, so that one will run to completion. 187 hedge_request.emit(:refuse) 188 end 189 ensure 190 self.hedge_request = nil 191 end
hedge_request=(request)
[show source]
# File lib/httpx/plugins/hedging.rb 144 def hedge_request=(request) 145 @hedge_request = request 146 147 return unless request 148 149 @is_hedge_request = !request.hedge_request.nil? 150 151 return if @is_hedge_request 152 153 request.hedge_request = self 154 end
response=(response)
[show source]
# File lib/httpx/plugins/hedging.rb 156 def response=(response) 157 return super unless @hedge_request # rubocop:disable Lint/ReturnInVoidContext 158 159 prev_response = @response 160 161 begin 162 super 163 ensure 164 @response = prev_response if prev_response 165 end 166 end