-
Notifications
You must be signed in to change notification settings - Fork 981
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
read timeout request option (part 2) #1022
read timeout request option (part 2) #1022
Conversation
Right now `timeout` setting sets all the timeout values (`read`, `open` & `write` if available). To unify the API with `Net::HTTP` one (which has a dedicated method for `read_timeout` as well) I propose extending the `RequestOptions` by `read_timeout`.
…ngerigor/faraday into springerigor-read-timeout-request-option
This allows adapter internals and specs to treat request options as a plain hash.
|
||
opts[:connect_timeout] = open_timeout | ||
opts[:connect_timeout] = sec |
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.
Rubocop forced me to turn this into a guard check ^^^
I updated the EMHttp and Excon adapters with positive results and one small issue: the internal adapter code treats the Externally, end users should never be able to pass a plain request options hash. Faraday will handle this conversion. But, a lot of specs tend to pass in plain hashes. So, I moved That will let us clean the timeout option logic a bit, while still (mostly) treating the request options as a hash. However, other Options classes have methods on them. Even faraday/lib/faraday/adapter/excon.rb Lines 19 to 24 in b35f6a2
Big Question Time: Are we cool with adding methods to the Options classes, or should we strive to move that logic to Personally, I'd like to bring |
It really depends on what meaning we give to the option classes. They are simple Structs, not fully-fledged classes. In my mind, this means they should only be used to store values and provide getter/setters methods. Any other method or logic should NOT be defined there. That said, I guess we're a bit borderline here. |
I agree, to a point. I like the properties on some of the options classes that only operate on the config properties themselves. Examples:
Possibly, but most of the options are accessed as symbol hash keys. A module Faraday
class RequestOptions # ...
def [](key)
key_sym = key.to_sym
case key_sym
when :read_timeout then super(:timeout) || super(key)
else super(key)
end
end Currently I'm leaning towards sticking with EDIT: Just realized I flipped my position from the last comment. Clearly I'm not too tied to any option (pun not intended). While thinking about this issue, I considered reverting the Options objects to plain hashes as a task for Faraday 2, which is why I'm now leaning towards Also, the F2 wishlist (#953) includes "Remove Options structs in favor of properties on Client/Request/Response", so I clearly not thrilled with the current Options implementation. |
Right, considering the access to properties through symbols, it seems like |
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.
I'm in favor of the change, and I've made tiny notes inline, sometimes as GitHub Suggestions, other times as text.
Hope this helps!
lib/faraday/adapter.rb
Outdated
# @return [Integer, nil] Timeout duration in seconds, or nil if no timeout | ||
# has been set. | ||
def request_timeout(type, options) | ||
key = TIMEOUT_KEYS[type] |
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.
Could use a key = TIMEOUT_KEYS.fetch(type) do ... end
and raise the error in there?
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.
(We can do that in a follow-up PR, no biggie.)
Co-Authored-By: Olle Jonsson <[email protected]>
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.
LGTM!
68c53c4
Thanks for the reviews 👋 |
This extends #1003 by adding
Faraday::RequestOptions#fetch_timeout
to clean up the logic of#configure_request
in the net/http adapter. Instead of checking forreq[:timeout]
before the more specific timeout settings in the adapter, this happens in#fetch_timeout
.If this pattern is okay, I'll update the other adapters to use
#fetch_timeout
, ensuring they all properly support the newread_timeout
setting. I'm open to other ideas, or even just different names.