Skip to content

Commit

Permalink
No need for print with \n, puts is thread safe since 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
baelter committed Nov 1, 2024
1 parent 8c2e79b commit 562cebb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/sparoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def write_cache
def public_ip(host = "checkip.amazonaws.com", port = 80) # rubocop:disable Metrics/MethodLength
Socket.tcp(host, port, connect_timeout: 3) do |sock|
sock.sync = true
sock.print "GET / HTTP/1.1\r\nHost: #{host}\r\nConnection: close\r\n\r\n"
sock.puts "GET / HTTP/1.1\r\nHost: #{host}\r\nConnection: close\r\n\r"
status = sock.readline(chomp: true)
raise(ResolvError, "#{host}:#{port} response: #{status}") unless status.start_with? "HTTP/1.1 200 "

Expand Down
6 changes: 3 additions & 3 deletions test/sparoid_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def test_it_resolves_public_ip_only_once_per_instance # rubocop:disable Metrics/
assert_match "Host: ", client.readline(chomp: true)
assert_equal "Connection: close", client.readline(chomp: true)

client.print "HTTP/1.1 200 OK\r\n"
client.print "Content-Length: #{client_ip.bytesize}\r\n"
client.print "\r\n"
client.puts "HTTP/1.1 200 OK\r"
client.puts "Content-Length: #{client_ip.bytesize}\r"
client.puts "\r"
client.print client_ip
client.close
server.close
Expand Down

0 comments on commit 562cebb

Please sign in to comment.