Skip to content

Commit f2cd8e7

Browse files
Merge branch 'master' into preserve-headers-option
2 parents 103532a + b31db8d commit f2cd8e7

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

lib/net/http.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_p
10791079
elsif p_addr == :ENV then
10801080
http.proxy_from_env = true
10811081
else
1082-
if p_addr && p_no_proxy && !URI::Generic.use_proxy?(p_addr, p_addr, p_port, p_no_proxy)
1082+
if p_addr && p_no_proxy && !URI::Generic.use_proxy?(address, address, port, p_no_proxy)
10831083
p_addr = nil
10841084
p_port = nil
10851085
end

lib/net/http/response.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ def read_body(dest = nil, &block)
366366
@body = nil
367367
end
368368
@read = true
369+
return if @body.nil?
369370

370371
case enc = @body_encoding
371372
when Encoding, false, nil
@@ -639,7 +640,7 @@ def read_chunked(dest, chunk_data_io) # :nodoc:
639640
end
640641

641642
def stream_check
642-
raise IOError, 'attempt to read body out of block' if @socket.closed?
643+
raise IOError, 'attempt to read body out of block' if @socket.nil? || @socket.closed?
643644
end
644645

645646
def procdest(dest, block)

test/net/http/test_http.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ def test_proxy_address
126126

127127
def test_proxy_address_no_proxy
128128
TestNetHTTPUtils.clean_http_proxy_env do
129-
http = Net::HTTP.new 'hostname.example', nil, 'proxy.example', nil, nil, nil, 'example'
129+
http = Net::HTTP.new 'hostname.example', nil, 'proxy.com', nil, nil, nil, 'example'
130130
assert_nil http.proxy_address
131131

132-
http = Net::HTTP.new '10.224.1.1', nil, 'proxy.example', nil, nil, nil, 'example,10.224.0.0/22'
132+
http = Net::HTTP.new '10.224.1.1', nil, 'proxy.com', nil, nil, nil, 'example,10.224.0.0/22'
133133
assert_nil http.proxy_address
134134
end
135135
end

test/net/http/test_httpresponse.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,41 @@ def test_read_body_string
589589
assert_equal 'hello', body
590590
end
591591

592+
def test_read_body_receiving_no_body
593+
io = dummy_io(<<EOS)
594+
HTTP/1.1 204 OK
595+
Connection: close
596+
597+
EOS
598+
599+
res = Net::HTTPResponse.read_new(io)
600+
res.body_encoding = 'utf-8'
601+
602+
body = 'something to override'
603+
604+
res.reading_body io, true do
605+
body = res.read_body
606+
end
607+
608+
assert_equal nil, body
609+
assert_equal nil, res.body
610+
end
611+
612+
def test_read_body_outside_of_reading_body
613+
io = dummy_io(<<EOS)
614+
HTTP/1.1 200 OK
615+
Connection: close
616+
Content-Length: 0
617+
618+
EOS
619+
620+
res = Net::HTTPResponse.read_new(io)
621+
622+
assert_raise IOError do
623+
res.read_body
624+
end
625+
end
626+
592627
def test_uri_equals
593628
uri = URI 'http://example'
594629

test/net/http/test_https.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def test_session_reuse
148148
# support session resuse. Limiting the version to the TLSv1.2 stack allows
149149
# this test to continue to work on LibreSSL 3.2+. LibreSSL may eventually
150150
# support session reuse, but there are no current plans to do so.
151-
http.ssl_version = :TLSv1
151+
http.ssl_version = :TLSv1_2
152152
end
153153

154154
http.start

0 commit comments

Comments
 (0)