You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

48 lines
963 B

#' Convert an 'httr' call to 'curl' command line
#'
#' @param complete_httr_verb_call wrap an `httr` `VERB` call with this function
#' and it will return the text of a working `curl` command line
#' @export
#' @examples \dontrun{
#' h2c(
#' httr::GET(
#' url = "https://rud.is/",
#' httr::user_agent(splashr::ua_apple_tv),
#' query = list(
#' a = "b",
#' c = 1
#' )
#' )
#' )
#' }
h2c <- function(complete_httr_verb_call) {
ƒ_call <- substitute(complete_httr_verb_call)
perl <- find_perl()
args <- system.file("bin", "h2c.pl", package = "httr2curl")
capture.output(
capture.output(
httr::with_verbose(
eval(ƒ_call)
), type = "message") -> res
) -> junk
out <- tempfile()
res[grepl("^->", res)] %>%
sub("^-> ", "", .) %>%
paste0(collapse = "\n") %>%
writeLines(out)
processx::run(
command = perl,
args = args,
stdin = out
) -> res
res$stdout
}