lib/httpx/connection/http1.rb in httpx-0.12.0 vs lib/httpx/connection/http1.rb in httpx-0.13.0
- old
+ new
@@ -8,11 +8,11 @@
include Loggable
MAX_REQUESTS = 100
CRLF = "\r\n"
- attr_reader :pending
+ attr_reader :pending, :requests
def initialize(buffer, options)
@options = Options.new(options)
@max_concurrent_requests = @options.max_concurrent_requests || MAX_REQUESTS
@max_requests = @options.max_requests || MAX_REQUESTS
@@ -67,11 +67,10 @@
return
end
return if @requests.include?(request)
- request.once(:headers, &method(:set_protocol_headers))
@requests << request
@pipelining = true if @requests.size > 1
end
def consume
@@ -234,10 +233,12 @@
throw(:called)
end
def disable_pipelining
return if @requests.empty?
+ # do not disable pipelining if already set to 1 request at a time
+ return if @max_concurrent_requests == 1
@requests.each do |r|
r.transition(:idle)
# when we disable pipelining, we still want to try keep-alive.
@@ -279,9 +280,10 @@
buffer = +""
buffer << "#{request.verb.to_s.upcase} #{headline_uri(request)} HTTP/#{@version.join(".")}" << CRLF
log(color: :yellow) { "<- HEADLINE: #{buffer.chomp.inspect}" }
@buffer << buffer
buffer.clear
+ set_protocol_headers(request)
request.headers.each do |field, value|
buffer << "#{capitalized(field)}: #{value}" << CRLF
log(color: :yellow) { "<- HEADER: #{buffer.chomp}" }
@buffer << buffer
buffer.clear