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

Add .netrc & cookie support #103

Closed
evetion opened this issue Feb 26, 2021 · 6 comments
Closed

Add .netrc & cookie support #103

evetion opened this issue Feb 26, 2021 · 6 comments

Comments

@evetion
Copy link
Sponsor Member

evetion commented Feb 26, 2021

Netrc files can store logins (username, password) for external websites, so you don't need to provide them in the url when accessing these websites. If used for an central authentication service, reading cookies in the current session is also required.

This setup is pretty common for accessing scientific datasets. For example: https://wiki.earthdata.nasa.gov/display/EL/How+To+Access+Data+With+cURL+And+Wget

I've made #98 to set these options as default. If this is unwarranted, can we discuss the design to support these as keyword arguments to the download function?

@evetion
Copy link
Sponsor Member Author

evetion commented Apr 13, 2021

In the meantime, this is the way to do it with the current package, based on some of the tests:

downloader = Downloads.Downloader()
easy_hook = (easy, info) -> begin
    Downloads.Curl.setopt(easy, Downloads.Curl.CURLOPT_NETRC, Downloads.Curl.CURL_NETRC_OPTIONAL)
    Downloads.Curl.setopt(easy, Downloads.Curl.CURLOPT_COOKIEFILE, "")
end
downloader.easy_hook = easy_hook

download(kwargs...) = Downloads.download(kwargs...;downloader=downloader)

@StefanKarpinski
Copy link
Sponsor Member

Yes, you've discovered that Downloader already supports setting any option that libcurl knows about 😸. I'm reluctant to officially document this since I'm not 100% on the API, primarily because it's not composable: if one bit of code sets an easy_hook and then another bit of code does too, it will clobber the earlier one. Perhaps a way to address that would be to have a stack of easy_hooks and when someone registers a hook it goes on the stack and they all get called in order.

@evetion
Copy link
Sponsor Member Author

evetion commented Apr 13, 2021

Yeah, I agree this shouldn't be the documented API for end-users. Not only because of the composability, but also because it's quite unfriendly for end users to know about CURL_XXX stuff or (stacks of) easy hooks.

I'd expect a high level API like download(...; compressed=true, netrc=true), following a subset of the curl command line interface arguments. This connects to a lower level API for the mapping from those kwargs on the (stack of) easy hooks for more advanced options. We could call it EasyEasy, Easy2 or ExtraEasy? 🙉

@StefanKarpinski
Copy link
Sponsor Member

I meant a literal stack, like a vector of hooks, not a sequence of hook names. It could be an official "workaround API".

@evetion
Copy link
Sponsor Member Author

evetion commented Apr 14, 2021

Wouldn't it be nicer to already squash that stack into a Dict like structure so it's clear which options will actually be used?

@evetion
Copy link
Sponsor Member Author

evetion commented Apr 14, 2021

Closed by #98.

@evetion evetion closed this as completed Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants