From ba4495d75afafaceb3c5a0d3b9d34d972717aa67 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 3 Jul 2024 16:09:21 +0900 Subject: [PATCH] [rubygems/rubygems] Align code styles with rubocop and others. https://github.com/rubygems/rubygems/commit/c31a1592ee --- .../test_gem_remote_fetcher_local_server.rb | 12 ++++-------- .../test_gem_remote_fetcher_local_ssl_server.rb | 14 ++++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/test/rubygems/test_gem_remote_fetcher_local_server.rb b/test/rubygems/test_gem_remote_fetcher_local_server.rb index 4b7af31b2c..4a408e3bf3 100644 --- a/test/rubygems/test_gem_remote_fetcher_local_server.rb +++ b/test/rubygems/test_gem_remote_fetcher_local_server.rb @@ -86,7 +86,7 @@ gems: end def teardown - @fetcher.close_all if @fetcher + @fetcher&.close_all if @normal_server @normal_server.kill.join @@ -186,7 +186,7 @@ gems: end def start_server(data) - server = TCPServer.new('localhost', 0) + server = TCPServer.new("localhost", 0) thread = Thread.new do loop do client = server.accept @@ -201,16 +201,12 @@ gems: request_line = client.gets headers = {} while (line = client.gets) && line != "\r\n" - key, value = line.split(': ', 2) + key, value = line.split(": ", 2) headers[key] = value.strip end if request_line.start_with?("GET /yaml") - response = if headers["X-Captain"] - headers["X-Captain"] - else - data - end + response = headers["X-Captain"] ? headers["X-Captain"] : data client.print "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: #{response.size}\r\n\r\n#{response}" elsif request_line.start_with?("HEAD /yaml") || request_line.start_with?("GET http://") && request_line.include?("/yaml") client.print "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: #{data.size}\r\n\r\n#{data}" diff --git a/test/rubygems/test_gem_remote_fetcher_local_ssl_server.rb b/test/rubygems/test_gem_remote_fetcher_local_ssl_server.rb index ad99de4414..85de129842 100644 --- a/test/rubygems/test_gem_remote_fetcher_local_ssl_server.rb +++ b/test/rubygems/test_gem_remote_fetcher_local_ssl_server.rb @@ -36,7 +36,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== def teardown if @ssl_server - # TODO lookup ssl_server status and close it properly + # TODO: lookup ssl_server status and close it properly # @ssl_server.shutdown @ssl_server = nil end @@ -162,13 +162,11 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg== loop do ssl_client = ssl_server.accept Thread.new(ssl_client) do |client| - begin - handle_request(client) - rescue OpenSSL::SSL::SSLError => e - warn "SSL error: #{e.message}" - ensure - client.close - end + handle_request(client) + rescue OpenSSL::SSL::SSLError => e + warn "SSL error: #{e.message}" + ensure + client.close end end end