Module: HTTPX::Plugins::Hedging::RequestMethods

Defined in:
lib/httpx/plugins/hedging.rb,
sig/plugins/hedging.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connection ⇒ Object (readonly)

TODO: would be nice to get rid of this



135
136
137
# File 'lib/httpx/plugins/hedging.rb', line 135

def connection
  @connection
end

#hedge_request ⇒ requestHedging?

Returns the value of attribute hedge_request.

Returns:

  • (requestHedging, nil)


137
138
139
# File 'lib/httpx/plugins/hedging.rb', line 137

def hedge_request
  @hedge_request
end

Instance Method Details

#emit_response(response) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/httpx/plugins/hedging.rb', line 168

def emit_response(response)
  hedge_request = @hedge_request

  return super unless hedge_request

  return super unless hedge_request &&
                      (
                        hedge_request.response.nil? ||
                        !hedge_request.response.finished?
                      )

  # if this response is for a hedge request, and the main request
  # didn't complete yet, then we replace it.

  super.tap do
    hedge_request.response = response

    # should cancel any pending HTTP/2 stream; there's no way to
    # cancel an HTTP/1 request, so that one will run to completion.
    hedge_request.emit(:refuse)
  end
ensure
  self.hedge_request = nil
end

#initialize ⇒ Object



139
140
141
142
# File 'lib/httpx/plugins/hedging.rb', line 139

def initialize(*)
  super
  @is_hedge_request = false
end

#response=(response) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/httpx/plugins/hedging.rb', line 156

def response=(response)
  return super unless @hedge_request # rubocop:disable Lint/ReturnInVoidContext

  prev_response = @response

  begin
    super
  ensure
    @response = prev_response if prev_response
  end
end