-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Using easy_hook
for per-request parameters
#141
Comments
Another example of this: AWS.jl has a new Downloads-based backend (JuliaCloud/AWS.jl#396) but they needed to set |
For the redirects case we ran into in AWS.jl, I think it could make sense to expose a But for the general case, I agree it would be good to be able to configure this on a per-request basis. My understanding is you often do want a shared downloader object in order to re-use connections and things like that, which is why the possible solution of "just make a new downloader globally configured how you want" isn't ideal in general. So I think it would be good to be able to configure this on a per-request level. |
For per-request modification of the download(url) do easy
Curl.setopt(easy, Curl.CURLOPT_WHATEVER, value)
end I don't know if it's worth using the do block syntax for this, but alternatively one could do this: download(url, easy_hook = easy->Curl.setopt(easy, Curl.CURLOPT_WHATEVER, value)) This raises the question: is this callback called in addition to the easy hook that's registered with the
That's a change to how the easy hooks work; maybe we'd want to make it an official API. |
I think this can already be done in a round about way — if the user has a |
Yes, but the point is that if multiple independent parties have set easy hooks, currently it will break. Instead, we would like for that to work. |
Can't independent parties just use their own For the global I could be persuaded otherwise. Do you have a particular use case in mind where it would be useful to compose global options without a central authority (ie, the application) knowing the complete list? |
Right, but it's fairly common for someone to want to set libcurl options that will affect the global downloader because they're needed to make download operations done somewhere else work. Suppose, for example, someone wants to inject some auth header when making requests to certain hosts. Someone else wants to set some other option. That could be made to work. Obviously, if you're in a position to inject a custom downloader into the download operation, that's better, but that's not always the case. Being able to set options on a single download is sufficient for anything if you control the download code but that's not always the case. |
Currently the
easy_hook
function gets passed aninfo
parameter with URL, method and headers:Downloads.jl/src/Downloads.jl
Lines 341 to 342 in e22219f
But I can't see how to use this to set options on a per-request basis as HTTP.jl currently allows for things like the connection timeout (https://curl.se/libcurl/c/CURLOPT_CONNECTTIMEOUT.html). Ideally we'd add connection timeouts and some other obviously useful parameters (will post a separate issue about those), but to cover more unforeseen settings it would be helpful if there was some way to get per-request items into the
info
struct.I'm not sure what's best for the API. A couple of possible ideas:
easy_hook_opts::Any=nothing
keyword torequest
, and just pass this through in theinfo
tuple.easy_hook::Union{Function,Nothing}=nothing
keyword torequest
and invoke this on the easy handle (maybe in addition to the easy hook which is contained in theDownloader
).I kind of favor the second of these ideas. Perhaps not as a public part of the API, but as an escape hatch it sure would be handy.
The text was updated successfully, but these errors were encountered: