Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/http/network/tcp_socket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require "socket"

module HTTP
module Network
class TCPSocket
class << self
def new(...)
::Socket.tcp(...)
end

def open(...)
new(...)
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/http/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

require "http/headers"
require "openssl"
require "socket"
require "http/network/tcp_socket"
require "http/uri"

module HTTP
class Options # rubocop:disable Metrics/ClassLength
@default_socket_class = TCPSocket
@default_socket_class = Network::TCPSocket
@default_ssl_socket_class = OpenSSL::SSL::SSLSocket
@default_timeout_class = HTTP::Timeout::Null
@available_features = {}
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/http/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def on_error(request, error)
end

it "is given a chance to handle a connection timeout error" do
allow(TCPSocket).to receive(:open) { sleep 1 }
allow(HTTP::Network::TCPSocket).to receive(:open) { sleep 1 }
sleep_url = "#{dummy.endpoint}/sleep"
feature_instance = feature_class.new

Expand Down Expand Up @@ -570,7 +570,7 @@ def wrap_response(res)
allow(socket_spy).to receive(:readpartial) { chunks.shift || :eof }
allow(socket_spy).to receive(:write) { chunks[0].length }

allow(TCPSocket).to receive(:open) { socket_spy }
allow(HTTP::Network::TCPSocket).to receive(:open) { socket_spy }
end

it "properly reads body" do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/http_handling_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
let(:response) { client.get(server.endpoint).body.to_s }

it "errors if connecting takes too long" do
expect(TCPSocket).to receive(:open) do
expect(HTTP::Network::TCPSocket).to receive(:open) do
sleep 1.25
end

Expand Down
Loading