-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow HTTP::Client to work with any IO #9543
Conversation
Wait what? That sounds like a big foot gun right there. I think calling Tests? :) |
Also documentation of this method, and maybe an embedded example 🙇 |
I had actually thought about this some time agoe. But it couldn't work without #9210. As @jhass mentioned, the |
Why can't we make breaking changes when we release 1.0.0? In my mind that release sounds like the biggest breaking change ever so that later there are no breaking changes. |
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
We can make breaking changes, but those might not have good time of deprecation notice. I wouldn't avoid doing it anyway if we think it's worth it. |
I think this wouldn't be a huge breaking change, as being able to reuse a |
The socket is re-created because the api can be used like this: HTTP::Client.new(...) do |client|
client.get ...
client.post ...
end Within the block the connection might be the same or not, depending on wether the server/protocol supports the keep alive. Or the connection might be a different one, if a connection pool were implemented. Then the |
I just implemented what @straight-shoota suggested, disabling autoreconnection only when initialized with Lines 747 to 748 in 476486e
Should we change the name of the instance var? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good then now. I think the name of the instance var is fine, we can the noise of renaming it to a bigger refactor.
I still would prefer close
to set @reconnect = false
ASAP. Despite being documented right now otherwise, I find that behavior still counter intuitive. We could offer a connect
kind of API to set/create the socket, keeping @reconnect
to false
for calls like connect(some_io)
but resetting it to true
for calls like connect(some_host)
, sort of mirroring the HTTP::Server#bind
API. But totally out of scope here.
Na, I wouldn't touch that until the entire HTTP::Client implementation gets revisited. It's on my to-do-after-1.0 list. But the list is actually quite long. 😆 |
Ideally, when using with an IO the client should not set a default host header unless explicitly asked told. The current default |
The If you have ideas for the HTTP::Client post 1.0 I suggest we review them now, at least to tune the API to avoid breaking changes after the release. I'd love to see a more flexible HTTP client built-in in the std, but I don't have specific plans in mind. |
Correction: according to the RFC, seems like the |
Yes, the host header is mandatory, but it should be empty if there's no meaningful value. My ideas about |
I think another thing that should happen is to have |
Well.. finally I renamed the ivar 🙈 |
Just a note that the old annotation, I'd still like #9052 to be considered because it would fix that problem (the ivar would actually be that union type, never go to the parent type). |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Rename `HTTPClient@socket` to `HTTPClient@io`, see crystal-lang/crystal#9543. Rename `URI#full_path` to `URI#request_target`, see crystal-lang/crystal#10099.
Rename `HTTPClient@socket` to `HTTPClient@io`, see crystal-lang/crystal#9543. Rename `URI#full_path` to `URI#request_target`, see crystal-lang/crystal#10099.
I know there was attempts to make
HTTP::Client
more generic. In the long term that would be desirable to support connection pools or socket factories. But this change was so easy and allow other scenarios currently unsupported. For example, talk through UNIX socket. The added initializer looks ugly because still needs to fillhost
andport
but those are used for theHost
header anyway. Another option is just make the@socket
available through a property so it can be externally set. The issue I found is that ifclose
is called the next request will try to open aTCPSocket
.Dunno, again this feel incomplete but it's a simple change that open possibilities.