Skip to content

Instantly share code, notes, and snippets.

@fagci
Forked from steveyen/gist:1201110
Last active September 21, 2022 06:20
Show Gist options
  • Save fagci/558f2a952cdf894f6c2d7ed9d439cfe7 to your computer and use it in GitHub Desktop.
Save fagci/558f2a952cdf894f6c2d7ed9d439cfe7 to your computer and use it in GitHub Desktop.
Using TCP_NODELAY with ruby Net HTTP (set socket options)
class MyHTTP < Net::HTTP
def on_connect()
@socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
end
end
n = 5
host = 'example.com'
port = 80
MyHTTP.new(host, port).start do |http|
n.times do
req = Net::HTTP::Get.new("http://#{host}:#{port}/rest/of/url")
req.add_field('Connection', 'keep-alive')
http.request(req) do |res|
res.read_body
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment