-
Notifications
You must be signed in to change notification settings - Fork 282
change calls from RCurl to curl package #2786
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
Conversation
don't know what to enter in the "type" argument and I am still not sure that form_file is the ideal function to replace the POSTFORM function.
|
@infotroph tried my best to update convert.input file.although I am not at all sure that form_file would be an ideal function to replace POSTFORM function. hhtr::POST might be the ideal choice as you said. |
infotroph
left a comment
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've only looked at convert_input.R so far, but posting this to save my comments and will come back to it as soon as I have time. Thanks for your patience.
| out.html <- RCurl::getURL(paste0("http://dap-dev.ncsa.illinois.edu:8184/inputs/", | ||
| browndog$inputtype), .opts = curloptions) | ||
| out.html <- curl::curl_download(paste0("http://dap-dev.ncsa.illinois.edu:8184/inputs/", | ||
| browndog$inputtype), curloptions) |
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 have not tested this yet, but it looks correct 👍
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.
On testing: curl_download writes to disk rather than returning a string. Probably want readLines(curl::curl(..., handle = hdl)), with curl options set beforehand via handle_setopt(hdl, ...)
base/utils/R/convert.input.R
Outdated
|
|
||
| # post zipped file to Brown Dog | ||
| html <- RCurl::postForm(url, fileData = RCurl::fileUpload(zipfile), .opts = curloptions) | ||
| html <- curl::form_file(url, 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.
It looks like the recommended pattern for form posting is to build up the multipart request inside the handle, then pass the whole handle as a fetch. See this example in the curl vignette.
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.
@infotroph thanks for the review ,I'll start working on the other files .
| dir.create(basename(file), recursive = TRUE) | ||
| count <- 0 | ||
| while (!RCurl::url.exists(url, .opts = .opts) && count < timeout) { | ||
| while (!curl::curl_fetch_memory(url, handle = curl::new_handle(nobody = 1)) && count < timeout) { |
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 see two subtleties here:
- When the url doesn't exist,
curl_fetch memorywill still return a value that evaluates to TRUE, so we need to explicitly check the status code (e.g.(curl_fetch_memory(...)$status_code %/% 200) == 1) - More trickily, when the requested hostname can't be resolved
curl_fetch_memorywill throw an error whereasRCurl::url.existsjust returns FALSE. I'm not sure whether we need to handle this case or not but will ask around.
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.
@infotroph should we be using httr:HEAD then?
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.
Looks like httr::HEAD has the same behavior both with respect to status codes and with respect to erroring on unresolvable hostnames, so we don't need to switch because of those. However HEAD definitely shows the intention much clearly than the nobody = 1 incantation does, so it'd be worth using at least in packages that already import httr.
| f <- open(file, mode = "wb") | ||
| curl::curl_download(url, file, handle = curl::new_handle(.list = .opts)) | ||
| close(f) |
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.
| f <- open(file, mode = "wb") | |
| curl::curl_download(url, file, handle = curl::new_handle(.list = .opts)) | |
| close(f) | |
| curl::curl_download(url, file, handle = curl::new_handle(.list = .opts)) |
curl_download handles the opening and closing for us
|
|
||
| userpass <- paste(browndog$username, browndog$password, sep = ":") | ||
| curloptions <- list(userpwd = userpass, httpauth = 1L, followlocation = TRUE) | ||
| result <- RCurl::postForm(paste0(browndog$url, formatname, "/"), |
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 guessing this is intentionally incomplete for now and will use the same pattern you develop in convert.input, but here's a placeholder to remind us to finish it :)
|
Input requested: This PR will alter paging @robkooper as architect and @serbinsh as user with an ongoing troublesome retry-the-URL use case: Does [comment edited: Tagged the wrong Kooper.] |
|
|
|
Similar to comments on other PRs, was curious what's left to do on this one @moki1202 @infotroph |
@infotroph Apologies from my side. Don't know why I deleted this branch. Might have been early days. Let me know how I can help to complete this. |
|
Continuing work on this in PR #2944; closing this one |
infotroph
left a comment
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.
Apparently LAST YEAR I left a draft review unfinished, including some comments that would have been useful in later conversation. Posting now so they're visible to everyone else, with my apologies.
| html <- RCurl::postForm(url, fileData = RCurl::fileUpload(zipfile), .opts = curloptions) | ||
| h <- new_handle() | ||
| handle_setform(h, | ||
| fileData = curl::form_file(curl::curl_upload(zipfile, url)) |
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 still getting up to speed on this, but think this line will just be
| fileData = curl::form_file(curl::curl_upload(zipfile, url)) | |
| fileData = curl::form_file(zipfile) |
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 was wrong about this... see #2944)
| out.html <- RCurl::getURL(paste0("http://dap-dev.ncsa.illinois.edu:8184/inputs/", | ||
| browndog$inputtype), .opts = curloptions) | ||
| out.html <- curl::curl_download(paste0("http://dap-dev.ncsa.illinois.edu:8184/inputs/", | ||
| browndog$inputtype), curloptions) |
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.
On testing: curl_download writes to disk rather than returning a string. Probably want readLines(curl::curl(..., handle = hdl)), with curl options set beforehand via handle_setopt(hdl, ...)
No description provided.