httprb / http

HTTP (The Gem! a.k.a. http.rb) - a fast Ruby HTTP client with a chainable API, streaming support, and timeouts
MIT License
3.01k stars 321 forks source link

Implement RFC 8305, the "Happy Eyeballs". #793

Open midnight-wonderer opened 6 days ago

midnight-wonderer commented 6 days ago

Overview

This addresses https://github.com/httprb/http/issues/739.

Happy Eyeballs landed in Ruby for quite some time. :tada: https://bugs.ruby-lang.org/issues/20108

However, it does not reach HTTP.rb yet. This is because HTTP.rb uses TCPSocket.open by default.

Source traces

A baby step

In order to take advantage of the new feature. I alias default_socket_class to Socket.tcp so the connection logic will be handled by the Ruby layer of Socket.

Rough edges

For your information Socket.tcp has a lot of features beyond Happy Eyeballs. For example, it supports connect_timeout natively. What to do with https://github.com/httprb/http/blob/db6863ab48fdd77178078b3128a9db3d0ad6069a/lib/http/timeout/global.rb#L24 needs more discussions. This is just one aspect of it.

Nevertheless, this baby step would introduce minimal breaking changes. (or any changes at all) Providing more robust connections.