Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/net/http/persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,13 @@ def self.detect_idle_timeout uri, max = 10

attr_reader :verify_hostname


##
# Sets whether to ignore end-of-file when reading a response body
# with Content-Length headers.

attr_accessor :ignore_eof

##
# Creates a new Net::HTTP::Persistent.
#
Expand Down Expand Up @@ -515,6 +522,7 @@ def initialize name: nil, proxy: nil, pool_size: DEFAULT_POOL_SIZE
@max_retries = 1
@socket_options = []
@ssl_generation = 0 # incremented when SSL session variables change
@ignore_eof = nil

@socket_options << [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1] if
Socket.const_defined? :TCP_NODELAY
Expand Down Expand Up @@ -643,6 +651,7 @@ def connection_for uri
reset connection
end

http.ignore_eof = @ignore_eof if @ignore_eof
http.keep_alive_timeout = @idle_timeout if @idle_timeout
http.max_retries = @max_retries if http.respond_to?(:max_retries=)
http.read_timeout = @read_timeout if @read_timeout
Expand Down
20 changes: 19 additions & 1 deletion test/test_net_http_persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class BasicConnection
:read_timeout, :open_timeout, :keep_alive_timeout
attr_accessor :ciphers, :ssl_timeout, :ssl_version, :min_version,
:max_version, :verify_depth, :verify_mode, :cert_store,
:ca_file, :ca_path, :cert, :key
:ca_file, :ca_path, :cert, :key, :ignore_eof
attr_reader :req, :debug_output
def initialize
@started, @finished = 0, 0
Expand Down Expand Up @@ -1530,4 +1530,22 @@ def test_connection_pool_after_fork
connection.close
end
end

def test_ignore_eof
@http.ignore_eof = true

connection

@http.connection_for @uri do |c|
assert c.http.ignore_eof
end

@http.ignore_eof = false

connection

@http.connection_for @uri do |c|
assert !c.http.ignore_eof
end
end
end