mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-06 00:02:08 -04:00
adding persistent= setter to Request
this avoids the creation of another options object
This commit is contained in:
parent
6176afbf2c
commit
bc99188c80
@ -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
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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?
|
||||
|
Loading…
x
Reference in New Issue
Block a user