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

Adding additional proxy settings #339

Open
alfirrell opened this issue Apr 16, 2020 · 3 comments
Open

Adding additional proxy settings #339

alfirrell opened this issue Apr 16, 2020 · 3 comments

Comments

@alfirrell
Copy link
Contributor

Is it possible to include a more generic way to set curl options? We have a need to supply additional curl options to those given in setHandleParameters() and get_api_cookies(), and to set the proxyuserpwd without a domain prefix.

Happy to submit a PR with an option, e.g. a setHandle <- function(handle) taking an arbitrary curl handle created by the user and assigning straight into .pkgenv[["cookie_handler"]]

@PMassicotte
Copy link
Owner

@eddelbuettel any thoughts?

@eddelbuettel
Copy link
Collaborator

Not an area I know that much about. As long as it is optional behavior I guess we could.

@alfirrell Can you also cook up a use case that needs it? Without, of course, exposing any tokens etc you may need?

@alfirrell
Copy link
Contributor Author

alfirrell commented Apr 16, 2020

Use-case wise, some specifics we'd want are to be able to specify timeout within the curl options, and to omit the domain. So effectively the curl handle we want is

example_timeout <- 60
# set options for the proxy
curl::handle_setopt(handle=cookie_handler,
                    .list=list(ssl_verifypeer=0L,
                               proxyuserpwd=paste0(.pkgenv[["handle_user"]],
                                                   ":",
                                                   .pkgenv[["handle_password"]]),
                               proxyauth=.pkgenv[["handle_proxyauth"]],
                               proxy=.pkgenv[["handle_proxyhost"]],
                               proxyport=.pkgenv[["handle_proxyport"]], 
                               timeout=example_timeout))

Could deal with the omitted domain issue by handling nulls better in the get_api_cookies (i.e. in the paste0, omit the '\\' if the domain is NULL). And could add timeout as another specific parameter in setHandleParameters(), but I wonder if it's easier to add a extra_curl_opts list of name-value pairs to pick up any extra curl params, which can the be passed direct into the .list in handle_setopt()

e.g.

setHandleParameters <- function(user = NULL, password = NULL, domain = NULL, proxyhost = NULL, proxyport = 8080, proxyauth = 15, extra_curl_opts = list()) {
  #assign all the params, plus...
  .pkgenv[["handle_extra_curl_opts"]] <- extra_curl_opts 
}

called with e.g. setHandleParameters("user", "pwd", extra_curl_opts = list(timeout = 60))
and then

cookie_handler <- curl::new_handle()
# set options for the proxy
# handle missing domain
proxy_domain <- ifelse(is.null(.pkgenv[["handle_domain"]]), "", paste0(.pkgenv[["handle_domain"]],"\\"))
proxy_user_pwd <- paste0(proxy_domain, .pkgenv[["handle_user"]],":",.pkgenv[["handle_password"]])

options_list <- list(ssl_verifypeer=0L, 
                     proxyuserpwd=proxy_user_pwd, 
                     proxyauth=.pkgenv[["handle_proxyauth"]],
                     proxy=.pkgenv[["handle_proxyhost"]],
                     proxyport=.pkgenv[["handle_proxyport"]])
options_list <- append(options_list, .pkgenv[["handle_extra_curl_opts"]])

curl::handle_setopt(handle=cookie_handler, .list=options_list)
cookie_req <- curl::curl_fetch_memory(cookie_url, handle = cookie_handler)

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

3 participants