diff --git a/lib/httpx/connection/http1.rb b/lib/httpx/connection/http1.rb index 48c18522..465976ec 100644 --- a/lib/httpx/connection/http1.rb +++ b/lib/httpx/connection/http1.rb @@ -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 diff --git a/lib/httpx/request.rb b/lib/httpx/request.rb index 4c42e551..8ed68b44 100644 --- a/lib/httpx/request.rb +++ b/lib/httpx/request.rb @@ -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 diff --git a/lib/httpx/session.rb b/lib/httpx/session.rb index da2c1383..688711b1 100644 --- a/lib/httpx/session.rb +++ b/lib/httpx/session.rb @@ -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)) diff --git a/sig/request.rbs b/sig/request.rbs index 5b770a7a..2363d17e 100644 --- a/sig/request.rbs +++ b/sig/request.rbs @@ -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?