diff --git a/NAMESPACE b/NAMESPACE index f7c4010..65019c9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,5 +5,5 @@ export(h2c) import(httr) import(processx) import(rvest) -import(xm2) +import(xml2) importFrom(magrittr,"%>%") diff --git a/R/h2c.R b/R/h2c.R index 1389eb0..4e335a1 100644 --- a/R/h2c.R +++ b/R/h2c.R @@ -38,18 +38,14 @@ h2c <- function(complete_httr_verb_call, use_web_service = FALSE) { httr::POST( url = "https://curl.se/h2c/", - httr:::content_type_json(), - body = list( - http = res - ), - encode = "form" + httr::user_agent("curl/7.64.1"), + httr::accept("*/*"), + httr::content_type("application/x-www-form-urlencoded"), + body = sprintf("http=%s", curl::curl_escape(res)), + encode = "raw" ) -> res1 - pg <- httr::content(res1) - - rvest::html_nodes(pg, xpath = ".//p[contains(., 'Command:')]/following-sibling::div[1]") %>% - rvest::html_text() %>% - trimws() + trimws(rawToChar(res1$content)) } else { @@ -65,7 +61,8 @@ h2c <- function(complete_httr_verb_call, use_web_service = FALSE) { stdin = out ) -> res - res$stdout + trimws(res$stdout) + } } \ No newline at end of file diff --git a/R/httr2curl-package.R b/R/httr2curl-package.R index f4512dd..09859b6 100644 --- a/R/httr2curl-package.R +++ b/R/httr2curl-package.R @@ -8,5 +8,5 @@ #' @name httr2curl #' @keywords internal #' @author Bob Rudis (bob@@rud.is) -#' @import httr processx rvest xm2 +#' @import httr processx rvest xml2 "_PACKAGE" diff --git a/README.md b/README.md index 6cbda4e..403e08e 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,7 @@ h2c( ) ) ) -## [1] "/var/folders/bx/41ph1lms22q9mc83j5tx4bg80000gn/T//RtmpFs8uvt/fileced55b4fcbba" -## [1] "curl --http2 --header \"Accept: application/json, text/xml, application/xml, */*\" --compressed --user-agent \"AppleTV6,2/11.1\" \"https://rud.is/?a=b&c=1\"\n" +## [1] "curl --http2 --header \"Accept: application/json, text/xml, application/xml, */*\" --compressed --user-agent \"AppleTV6,2/11.1\" \"https://rud.is/?a=b&c=1\"" ``` ### Using the web service @@ -79,18 +78,17 @@ h2c( ), use_web_service = TRUE ) -## [1] "/var/folders/bx/41ph1lms22q9mc83j5tx4bg80000gn/T//RtmpFs8uvt/fileced53c5bb06" -## NULL +## [1] "curl --header \"Accept: application/json, text/xml, application/xml, */*\" --compressed --user-agent \"AppleTV6,2/11.1\" \"https://rud.is/?a=b&c=1\"" ``` ## httr2curl Metrics | Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | |:-----|---------:|-----:|----:|-----:|------------:|-----:|---------:|-----:| -| R | 5 | 0.36 | 52 | 0.25 | 21 | 0.25 | 40 | 0.26 | +| R | 5 | 0.36 | 49 | 0.24 | 21 | 0.25 | 40 | 0.26 | | Rmd | 1 | 0.07 | 29 | 0.14 | 19 | 0.23 | 35 | 0.23 | | YAML | 1 | 0.07 | 22 | 0.11 | 2 | 0.02 | 2 | 0.01 | -| SUM | 7 | 0.50 | 103 | 0.50 | 42 | 0.50 | 77 | 0.50 | +| SUM | 7 | 0.50 | 100 | 0.50 | 42 | 0.50 | 77 | 0.50 | clock Package Metrics for httr2curl