Skip to content
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

Feature request: customize the value of CURLOPT_MAXREDIRS on a per-call basis #173

Closed
DilumAluthge opened this issue Jan 17, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@DilumAluthge
Copy link
Member

It looks like CURLOPT_MAXREDIRS is currently hard-coded to 50:

setopt(easy, CURLOPT_MAXREDIRS, 50)

This makes sense, since 50 is also the default for the command-line curl.

However, it would be nice if users could customize the value of CURLOPT_MAXREDIRS on a per-call basis. By "per-call basis", I mean that users could do something like this:

julia> resp_1 = request(url_1; maxredirs = 25)

julia> resp_2 = request(url_2; maxredirs = 100)

In this example, the value of maxredirs passed as a kwarg to the request function will only affect that individual call.

@DilumAluthge DilumAluthge added the enhancement New feature or request label Jan 17, 2022
@StefanKarpinski
Copy link
Sponsor Member

Why would you need to change it?

@StefanKarpinski
Copy link
Sponsor Member

At a higher level, we could expose every single option that libcurl has. I don't want to do that, which is why it's possible to add an easy_hook to directly set arbitrary curl options.

@DilumAluthge
Copy link
Member Author

which is why it's possible to add an easy_hook to directly set arbitrary curl options

That's probably what I should do. Do you have any example code for this?

@DilumAluthge
Copy link
Member Author

From looking at the test suite, I'm guessing it'll be something like this:

import Downloads

easy_hook = (easy, info) -> begin
    timeout_seconds = 120
    timeout_milliseconds = round(Clong, timeout_seconds * 1_000)
    Downloads.Curl.setopt(easy, Downloads.Curl.CURLOPT_TIMEOUT_MS, timeout_milliseconds)
end
downloader = Downloads.Downloader()
downloader.easy_hook = easy_hook

output_tempfile = Downloads.download("https://julialang.org/"; downloader = downloader)
output_contents = read(output_tempfile, String)

@DilumAluthge
Copy link
Member Author

I think that the ability to provide a custom easy_hookis exactly what I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants