Skip to content

Commit 366400f

Browse files
committed
More handle to localhost
And remove rescure
1 parent 205b88c commit 366400f

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

test/stdlib/Net_HTTP_test.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ def initialize(host)
1414
loop do
1515
s = @server.accept
1616

17-
while (line = s.gets) && !line.chomp.empty?
17+
content_length = nil
18+
while line = s.gets
19+
if line.start_with?('Content-Length:')
20+
content_length = line.split(':', 2)[1].strip.to_i
21+
end
22+
break if line == "\r\n"
23+
end
24+
if content_length
25+
s.read(content_length)
1826
end
1927

2028
begin
21-
s.write "HTTP/1.1 200 OK\r\n"
22-
s.write "Content-Type: text/plain\r\n"
23-
s.write "Content-Length: 0\r\n"
24-
s.write "Connection: close\r\n"
25-
s.write "\r\n"
26-
rescue
29+
s.write "HTTP/1.1 200 OK\r\n\r\n"
2730
ensure
2831
s.close
2932
end
@@ -43,7 +46,6 @@ def with_server(host)
4346
res = nil
4447
begin
4548
res = yield server.uri
46-
rescue
4749
ensure
4850
server.finish
4951
end
@@ -64,24 +66,24 @@ def test_get
6466
with_server("localhost") do |uri|
6567
assert_send_type "(URI::Generic) -> nil",
6668
Net::HTTP, :get_print, uri
67-
assert_send_type "(String, String) -> nil",
68-
Net::HTTP, :get_print, "www.ruby-lang.org", "/en"
69+
assert_send_type "(String, String, Integer) -> nil",
70+
Net::HTTP, :get_print, uri.host, "/en", uri.port
6971
assert_send_type "(URI::Generic, Hash[String, String]) -> nil",
7072
Net::HTTP, :get_print, uri, { "Accept" => "text/html" }
7173
assert_send_type "(URI::Generic, Hash[Symbol, String]) -> nil",
7274
Net::HTTP, :get_print, uri, { Accept: "text/html" }
7375
assert_send_type "(URI::Generic) -> String",
7476
Net::HTTP, :get, uri
75-
assert_send_type "(String, String) -> String",
76-
Net::HTTP, :get, "www.ruby-lang.org", "/en"
77+
assert_send_type "(String, String, Integer) -> String",
78+
Net::HTTP, :get, uri.host, "/en", uri.port
7779
assert_send_type "(URI::Generic, Hash[String, String]) -> String",
7880
Net::HTTP, :get, uri, { "Accept" => "text/html" }
7981
assert_send_type "(URI::Generic, Hash[Symbol, String]) -> String",
8082
Net::HTTP, :get, uri, { Accept: "text/html" }
8183
assert_send_type "(URI::Generic) -> Net::HTTPResponse",
8284
Net::HTTP, :get_response, uri
83-
assert_send_type "(String, String) -> Net::HTTPResponse",
84-
Net::HTTP, :get_response, "www.ruby-lang.org", "/en"
85+
assert_send_type "(String, String, Integer) -> Net::HTTPResponse",
86+
Net::HTTP, :get_response, uri.host, "/en", uri.port
8587
assert_send_type "(URI::Generic, Hash[String, String]) -> Net::HTTPResponse",
8688
Net::HTTP, :get_response, uri, { "Accept" => "text/html" }
8789
assert_send_type "(URI::Generic, Hash[Symbol, String]) -> Net::HTTPResponse",

0 commit comments

Comments
 (0)