adding persistent= setter to Request

this avoids the creation of another options object
This commit is contained in:
HoneyryderChuck 2023-10-22 23:23:02 +01:00
parent 6176afbf2c
commit bc99188c80
4 changed files with 14 additions and 2 deletions

View File

@ -294,7 +294,7 @@ module HTTPX
connection = request.headers["connection"]
connection ||= if request.options.persistent
connection ||= if request.persistent?
# when in a persistent connection, the request can't be at
# the edge of a renegotiation
if @requests.index(request) + 1 < @max_requests

View File

@ -38,6 +38,8 @@ module HTTPX
# Exception raised during enumerable body writes.
attr_reader :drain_error
attr_writer :persistent
# will be +true+ when request body has been completely flushed.
def_delegator :@body, :empty?
@ -63,6 +65,7 @@ module HTTPX
@body = @options.request_body_class.new(@headers, @options)
@state = :idle
@response = nil
@persistent = @options.persistent
end
# the read timeout defied for this requet.
@ -80,6 +83,10 @@ module HTTPX
@options.timeout[:request_timeout]
end
def persistent?
@persistent
end
def trailers?
defined?(@trailers)
end

View File

@ -83,7 +83,8 @@ module HTTPX
def build_request(verb, uri, options = EMPTY_HASH)
rklass = @options.request_class
options = @options.merge(options) unless options.is_a?(Options)
request = rklass.new(verb, uri, options.merge(persistent: @persistent))
request = rklass.new(verb, uri, options)
request.persistent = @persistent
request.on(:response, &method(:on_response).curry(2)[request])
request.on(:promise, &method(:on_promise))

View File

@ -15,6 +15,8 @@ module HTTPX
attr_reader response: response?
attr_reader drain_error: StandardError?
attr_writer persistent: bool
@trailers: Headers?
@informational_status: Integer?
@query: String?
@ -50,6 +52,8 @@ module HTTPX
def trailers?: () -> boolish
def persistent?: () -> bool
def read_timeout: () -> Numeric?
def write_timeout: () -> Numeric?