Skip to content

Commit

Permalink
Merge branch 'master' into preserve-headers-option
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanSiqueira authored Oct 30, 2023
2 parents 103532a + b31db8d commit f2cd8e7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_p
elsif p_addr == :ENV then
http.proxy_from_env = true
else
if p_addr && p_no_proxy && !URI::Generic.use_proxy?(p_addr, p_addr, p_port, p_no_proxy)
if p_addr && p_no_proxy && !URI::Generic.use_proxy?(address, address, port, p_no_proxy)
p_addr = nil
p_port = nil
end
Expand Down
3 changes: 2 additions & 1 deletion lib/net/http/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def read_body(dest = nil, &block)
@body = nil
end
@read = true
return if @body.nil?

case enc = @body_encoding
when Encoding, false, nil
Expand Down Expand Up @@ -639,7 +640,7 @@ def read_chunked(dest, chunk_data_io) # :nodoc:
end

def stream_check
raise IOError, 'attempt to read body out of block' if @socket.closed?
raise IOError, 'attempt to read body out of block' if @socket.nil? || @socket.closed?
end

def procdest(dest, block)
Expand Down
4 changes: 2 additions & 2 deletions test/net/http/test_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ def test_proxy_address

def test_proxy_address_no_proxy
TestNetHTTPUtils.clean_http_proxy_env do
http = Net::HTTP.new 'hostname.example', nil, 'proxy.example', nil, nil, nil, 'example'
http = Net::HTTP.new 'hostname.example', nil, 'proxy.com', nil, nil, nil, 'example'
assert_nil http.proxy_address

http = Net::HTTP.new '10.224.1.1', nil, 'proxy.example', nil, nil, nil, 'example,10.224.0.0/22'
http = Net::HTTP.new '10.224.1.1', nil, 'proxy.com', nil, nil, nil, 'example,10.224.0.0/22'
assert_nil http.proxy_address
end
end
Expand Down
35 changes: 35 additions & 0 deletions test/net/http/test_httpresponse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,41 @@ def test_read_body_string
assert_equal 'hello', body
end

def test_read_body_receiving_no_body
io = dummy_io(<<EOS)
HTTP/1.1 204 OK
Connection: close
EOS

res = Net::HTTPResponse.read_new(io)
res.body_encoding = 'utf-8'

body = 'something to override'

res.reading_body io, true do
body = res.read_body
end

assert_equal nil, body
assert_equal nil, res.body
end

def test_read_body_outside_of_reading_body
io = dummy_io(<<EOS)
HTTP/1.1 200 OK
Connection: close
Content-Length: 0
EOS

res = Net::HTTPResponse.read_new(io)

assert_raise IOError do
res.read_body
end
end

def test_uri_equals
uri = URI 'http://example'

Expand Down
2 changes: 1 addition & 1 deletion test/net/http/test_https.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_session_reuse
# support session resuse. Limiting the version to the TLSv1.2 stack allows
# this test to continue to work on LibreSSL 3.2+. LibreSSL may eventually
# support session reuse, but there are no current plans to do so.
http.ssl_version = :TLSv1
http.ssl_version = :TLSv1_2
end

http.start
Expand Down

0 comments on commit f2cd8e7

Please sign in to comment.