|
@ -2,6 +2,8 @@ |
|
|
#' |
|
|
#' |
|
|
#' @param complete_httr_verb_call wrap an `httr` `VERB` call with this function |
|
|
#' @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 |
|
|
#' and it will return the text of a working `curl` command line |
|
|
|
|
|
#' @param use_web_service if `TRUE` (`FALSE` by default) this function will use |
|
|
|
|
|
#' `https://curl.se/h2c/` to process the headers. |
|
|
#' @export |
|
|
#' @export |
|
|
#' @examples \dontrun{ |
|
|
#' @examples \dontrun{ |
|
|
#' h2c( |
|
|
#' h2c( |
|
@ -15,14 +17,10 @@ |
|
|
#' ) |
|
|
#' ) |
|
|
#' ) |
|
|
#' ) |
|
|
#' } |
|
|
#' } |
|
|
h2c <- function(complete_httr_verb_call) { |
|
|
h2c <- function(complete_httr_verb_call, use_web_service = FALSE) { |
|
|
|
|
|
|
|
|
ƒ_call <- substitute(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( |
|
|
capture.output( |
|
|
capture.output( |
|
|
httr::with_verbose( |
|
|
httr::with_verbose( |
|
@ -34,8 +32,32 @@ h2c <- function(complete_httr_verb_call) { |
|
|
|
|
|
|
|
|
res[grepl("^->", res)] %>% |
|
|
res[grepl("^->", res)] %>% |
|
|
sub("^-> ", "", .) %>% |
|
|
sub("^-> ", "", .) %>% |
|
|
paste0(collapse = "\n") %>% |
|
|
paste0(collapse = "\n") -> res |
|
|
writeLines(out) |
|
|
|
|
|
|
|
|
if (use_web_service) { |
|
|
|
|
|
|
|
|
|
|
|
httr::POST( |
|
|
|
|
|
url = "https://curl.se/h2c/", |
|
|
|
|
|
httr:::content_type_json(), |
|
|
|
|
|
body = list( |
|
|
|
|
|
http = res |
|
|
|
|
|
), |
|
|
|
|
|
encode = "form" |
|
|
|
|
|
) -> res1 |
|
|
|
|
|
|
|
|
|
|
|
pg <- httr::content(res1) |
|
|
|
|
|
|
|
|
|
|
|
rvest::html_nodes(pg, xpath = ".//p[contains(., 'Command:')]/following-sibling::div[1]") %>% |
|
|
|
|
|
rvest::html_text() %>% |
|
|
|
|
|
trimws() |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
writeLines(res, out) |
|
|
|
|
|
|
|
|
|
|
|
perl <- find_perl() |
|
|
|
|
|
|
|
|
|
|
|
args <- system.file("bin", "h2c.pl", package = "httr2curl") |
|
|
|
|
|
|
|
|
processx::run( |
|
|
processx::run( |
|
|
command = perl, |
|
|
command = perl, |
|
@ -44,5 +66,6 @@ h2c <- function(complete_httr_verb_call) { |
|
|
) -> res |
|
|
) -> res |
|
|
|
|
|
|
|
|
res$stdout |
|
|
res$stdout |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |