Browse Source

web service

master
boB Rudis 2 months ago
parent
commit
b42607c1e3
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
4 changed files with 14 additions and 19 deletions
  1. +1
    -1
      NAMESPACE
  2. +8
    -11
      R/h2c.R
  3. +1
    -1
      R/httr2curl-package.R
  4. +4
    -6
      README.md

+ 1
- 1
NAMESPACE View File

@ -5,5 +5,5 @@ export(h2c)
import(httr)
import(processx)
import(rvest)
import(xm2)
import(xml2)
importFrom(magrittr,"%>%")

+ 8
- 11
R/h2c.R View File

@ -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)
}
}

+ 1
- 1
R/httr2curl-package.R View File

@ -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"

+ 4
- 6
README.md View File

@ -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


Loading…
Cancel
Save