diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 448234c2..e9b2a13c 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -57,3 +57,5 @@ jobs: - uses: r-lib/actions/check-r-package@v2 env: CURL_SSL_BACKEND: ${{ matrix.config.ssl-backend }} + with: + args: 'c("--no-manual", "--as-cran", "--run-donttest")' diff --git a/NEWS b/NEWS index 2a811133..c34bfd0c 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ it works better with some GUIs. - multi_download() now sets mtime for downloaded files from server - Fix for multi_download() when downloading 0byte files + - Use a self hosted httpbin test server 5.0.0 - New function multi_download() which supports concurrent downloads and resuming diff --git a/R/curl.R b/R/curl.R index 70ff27b2..a438a16e 100644 --- a/R/curl.R +++ b/R/curl.R @@ -17,7 +17,7 @@ #' initially. Currently only "r" and "rb" are supported. #' @param handle a curl handle object #' @examples \dontrun{ -#' con <- curl("https://httpbin.org/get") +#' con <- curl("https://hb.r-universe.dev/get") #' readLines(con) #' #' # Auto-opened connections can be recycled @@ -27,20 +27,20 @@ #' rawToChar(bin) #' #' # HTTP error -#' curl("https://httpbin.org/status/418", "r") +#' curl("https://hb.r-universe.dev/status/418", "r") #' #' # Follow redirects -#' readLines(curl("https://httpbin.org/redirect/3")) +#' readLines(curl("https://hb.r-universe.dev/redirect/3")) #' #' # Error after redirect -#' curl("https://httpbin.org/redirect-to?url=http://httpbin.org/status/418", "r") +#' curl("https://hb.r-universe.dev/redirect-to?url=https://hb.r-universe.dev/status/418", "r") #' #' # Auto decompress Accept-Encoding: gzip / deflate (rfc2616 #14.3) -#' readLines(curl("http://httpbin.org/gzip")) -#' readLines(curl("http://httpbin.org/deflate")) +#' readLines(curl("https://hb.r-universe.dev/gzip")) +#' readLines(curl("https://hb.r-universe.dev/deflate")) #' #' # Binary support -#' buf <- readBin(curl("http://httpbin.org/bytes/98765", "rb"), raw(), 1e5) +#' buf <- readBin(curl("https://hb.r-universe.dev/bytes/98765", "rb"), raw(), 1e5) #' length(buf) #' #' # Read file from disk @@ -64,7 +64,7 @@ #' nycflights <- stream_in(con) #' } #' -curl <- function(url = "http://httpbin.org/get", open = "", handle = new_handle()){ +curl <- function(url = "https://hb.r-universe.dev/get", open = "", handle = new_handle()){ curl_connection(url, open, handle) } diff --git a/R/echo.R b/R/echo.R index 13f4f890..192ce39e 100644 --- a/R/echo.R +++ b/R/echo.R @@ -9,7 +9,7 @@ #' @param progress show progress meter during http transfer #' @param file path or connection to write body. Default returns body as raw vector. #' @examples if(require('httpuv')){ -#' h <- new_handle(url = 'https://httpbin.org/post') +#' h <- new_handle(url = 'https://hb.r-universe.dev/post') #' handle_setform(h, foo = "blabla", bar = charToRaw("test"), #' myfile = form_file(system.file("DESCRIPTION"), "text/description")) #' diff --git a/R/fetch.R b/R/fetch.R index a385b435..c3a14222 100644 --- a/R/fetch.R +++ b/R/fetch.R @@ -29,17 +29,19 @@ #' @rdname curl_fetch #' @useDynLib curl R_curl_fetch_memory #' @examples +#' \donttest{ #' # Load in memory -#' res <- curl_fetch_memory("http://httpbin.org/cookies/set?foo=123&bar=ftw") +#' res <- curl_fetch_memory("https://hb.r-universe.dev/cookies/set?foo=123&bar=ftw") #' res$content #' #' # Save to disk -#' res <- curl_fetch_disk("http://httpbin.org/stream/10", tempfile()) +#' res <- curl_fetch_disk("https://hb.r-universe.dev/stream/10", tempfile()) #' res$content #' readLines(res$content) #' #' # Stream with callback -#' res <- curl_fetch_stream("http://www.httpbin.org/drip?duration=3&numbytes=15&code=200", function(x){ +#' drip_url <- "https://hb.r-universe.dev/drip?duration=3&numbytes=15&code=200" +#' res <- curl_fetch_stream(drip_url, function(x){ #' cat(rawToChar(x)) #' }) #' @@ -52,11 +54,12 @@ #' failure <- function(msg){ #' cat("Oh noes! Request failed!", msg, "\n") #' } -#' curl_fetch_multi("http://httpbin.org/get", success, failure) -#' curl_fetch_multi("http://httpbin.org/status/418", success, failure) +#' curl_fetch_multi("https://hb.r-universe.dev/get", success, failure) +#' curl_fetch_multi("https://hb.r-universe.dev/status/418", success, failure) #' curl_fetch_multi("https://urldoesnotexist.xyz", success, failure) #' multi_run() #' str(data) +#' } curl_fetch_memory <- function(url, handle = new_handle()){ nonblocking <- isTRUE(getOption("curl_interrupt", TRUE)) output <- .Call(R_curl_fetch_memory, enc2utf8(url), handle, nonblocking) diff --git a/R/handle.R b/R/handle.R index f8efcac4..811e7963 100644 --- a/R/handle.R +++ b/R/handle.R @@ -31,14 +31,14 @@ #' h <- new_handle() #' handle_setopt(h, customrequest = "PUT") #' handle_setform(h, a = "1", b = "2") -#' r <- curl_fetch_memory("http://httpbin.org/put", h) +#' r <- curl_fetch_memory("https://hb.r-universe.dev/put", h) #' cat(rawToChar(r$content)) #' #' # Or use the list form #' h <- new_handle() #' handle_setopt(h, .list = list(customrequest = "PUT")) #' handle_setform(h, .list = list(a = "1", b = "2")) -#' r <- curl_fetch_memory("http://httpbin.org/put", h) +#' r <- curl_fetch_memory("https://hb.r-universe.dev/put", h) #' cat(rawToChar(r$content)) new_handle <- function(...){ h <- .Call(R_new_handle) @@ -140,11 +140,11 @@ handle_reset <- function(handle){ #' handle_cookies(h) #' #' # Server sets cookies -#' req <- curl_fetch_memory("http://httpbin.org/cookies/set?foo=123&bar=ftw", handle = h) +#' req <- curl_fetch_memory("https://hb.r-universe.dev/cookies/set?foo=123&bar=ftw", handle = h) #' handle_cookies(h) #' #' # Server deletes cookies -#' req <- curl_fetch_memory("http://httpbin.org/cookies/delete?foo", handle = h) +#' req <- curl_fetch_memory("https://hb.r-universe.dev/cookies/delete?foo", handle = h) #' handle_cookies(h) #' #' # Cookies will survive a reset! diff --git a/R/multi.R b/R/multi.R index ee534038..e3fed08b 100644 --- a/R/multi.R +++ b/R/multi.R @@ -65,12 +65,12 @@ #' cat(paste("Failed request:", str), file = stderr()) #' } #' # This handle will take longest (3sec) -#' h1 <- new_handle(url = "https://eu.httpbin.org/delay/3") +#' h1 <- new_handle(url = "https://hb.r-universe.dev/delay/3") #' multi_add(h1, done = success, fail = failure) #' #' # This handle writes data to a file #' con <- file("output.txt") -#' h2 <- new_handle(url = "https://eu.httpbin.org/post", postfields = "bla bla") +#' h2 <- new_handle(url = "https://hb.r-universe.dev/post", postfields = "bla bla") #' multi_add(h2, done = success, fail = failure, data = con) #' #' # This handle raises an error diff --git a/R/parse_headers.R b/R/parse_headers.R index ac7b80fb..85fea804 100644 --- a/R/parse_headers.R +++ b/R/parse_headers.R @@ -14,7 +14,7 @@ #' @param multiple parse multiple sets of headers separated by a blank line. See details. #' @export #' @rdname parse_headers -#' @examples req <- curl_fetch_memory("https://httpbin.org/redirect/3") +#' @examples req <- curl_fetch_memory("https://hb.r-universe.dev/redirect/3") #' parse_headers(req$headers) #' parse_headers(req$headers, multiple = TRUE) #' diff --git a/man/curl.Rd b/man/curl.Rd index 2b097883..8b949f8a 100644 --- a/man/curl.Rd +++ b/man/curl.Rd @@ -4,7 +4,7 @@ \alias{curl} \title{Curl connection interface} \usage{ -curl(url = "http://httpbin.org/get", open = "", handle = new_handle()) +curl(url = "https://hb.r-universe.dev/get", open = "", handle = new_handle()) } \arguments{ \item{url}{character string. See examples.} @@ -28,7 +28,7 @@ yet. } \examples{ \dontrun{ -con <- curl("https://httpbin.org/get") +con <- curl("https://hb.r-universe.dev/get") readLines(con) # Auto-opened connections can be recycled @@ -38,20 +38,20 @@ close(con) rawToChar(bin) # HTTP error -curl("https://httpbin.org/status/418", "r") +curl("https://hb.r-universe.dev/status/418", "r") # Follow redirects -readLines(curl("https://httpbin.org/redirect/3")) +readLines(curl("https://hb.r-universe.dev/redirect/3")) # Error after redirect -curl("https://httpbin.org/redirect-to?url=http://httpbin.org/status/418", "r") +curl("https://hb.r-universe.dev/redirect-to?url=https://hb.r-universe.dev/status/418", "r") # Auto decompress Accept-Encoding: gzip / deflate (rfc2616 #14.3) -readLines(curl("http://httpbin.org/gzip")) -readLines(curl("http://httpbin.org/deflate")) +readLines(curl("https://hb.r-universe.dev/gzip")) +readLines(curl("https://hb.r-universe.dev/deflate")) # Binary support -buf <- readBin(curl("http://httpbin.org/bytes/98765", "rb"), raw(), 1e5) +buf <- readBin(curl("https://hb.r-universe.dev/bytes/98765", "rb"), raw(), 1e5) length(buf) # Read file from disk diff --git a/man/curl_echo.Rd b/man/curl_echo.Rd index be906312..add4a6b9 100644 --- a/man/curl_echo.Rd +++ b/man/curl_echo.Rd @@ -21,7 +21,7 @@ echo the request body and content type in the response. } \examples{ if(require('httpuv')){ -h <- new_handle(url = 'https://httpbin.org/post') +h <- new_handle(url = 'https://hb.r-universe.dev/post') handle_setform(h, foo = "blabla", bar = charToRaw("test"), myfile = form_file(system.file("DESCRIPTION"), "text/description")) diff --git a/man/curl_fetch.Rd b/man/curl_fetch.Rd index 73ea0a29..5cc9d541 100644 --- a/man/curl_fetch.Rd +++ b/man/curl_fetch.Rd @@ -76,17 +76,19 @@ requests (when \code{curl_fetch_memory} would raise an error), the \code{fail} function is triggered with the error message. } \examples{ +\donttest{ # Load in memory -res <- curl_fetch_memory("http://httpbin.org/cookies/set?foo=123&bar=ftw") +res <- curl_fetch_memory("https://hb.r-universe.dev/cookies/set?foo=123&bar=ftw") res$content # Save to disk -res <- curl_fetch_disk("http://httpbin.org/stream/10", tempfile()) +res <- curl_fetch_disk("https://hb.r-universe.dev/stream/10", tempfile()) res$content readLines(res$content) # Stream with callback -res <- curl_fetch_stream("http://www.httpbin.org/drip?duration=3&numbytes=15&code=200", function(x){ +drip_url <- "https://hb.r-universe.dev/drip?duration=3&numbytes=15&code=200" +res <- curl_fetch_stream(drip_url, function(x){ cat(rawToChar(x)) }) @@ -99,9 +101,10 @@ success <- function(res){ failure <- function(msg){ cat("Oh noes! Request failed!", msg, "\n") } -curl_fetch_multi("http://httpbin.org/get", success, failure) -curl_fetch_multi("http://httpbin.org/status/418", success, failure) +curl_fetch_multi("https://hb.r-universe.dev/get", success, failure) +curl_fetch_multi("https://hb.r-universe.dev/status/418", success, failure) curl_fetch_multi("https://urldoesnotexist.xyz", success, failure) multi_run() str(data) } +} diff --git a/man/handle.Rd b/man/handle.Rd index 3f6af76d..7b4c024b 100644 --- a/man/handle.Rd +++ b/man/handle.Rd @@ -65,14 +65,14 @@ each request. There is very little performance overhead in creating handles. h <- new_handle() handle_setopt(h, customrequest = "PUT") handle_setform(h, a = "1", b = "2") -r <- curl_fetch_memory("http://httpbin.org/put", h) +r <- curl_fetch_memory("https://hb.r-universe.dev/put", h) cat(rawToChar(r$content)) # Or use the list form h <- new_handle() handle_setopt(h, .list = list(customrequest = "PUT")) handle_setform(h, .list = list(a = "1", b = "2")) -r <- curl_fetch_memory("http://httpbin.org/put", h) +r <- curl_fetch_memory("https://hb.r-universe.dev/put", h) cat(rawToChar(r$content)) } \seealso{ diff --git a/man/handle_cookies.Rd b/man/handle_cookies.Rd index 1849aaa3..2b524d32 100644 --- a/man/handle_cookies.Rd +++ b/man/handle_cookies.Rd @@ -18,11 +18,11 @@ h <- new_handle() handle_cookies(h) # Server sets cookies -req <- curl_fetch_memory("http://httpbin.org/cookies/set?foo=123&bar=ftw", handle = h) +req <- curl_fetch_memory("https://hb.r-universe.dev/cookies/set?foo=123&bar=ftw", handle = h) handle_cookies(h) # Server deletes cookies -req <- curl_fetch_memory("http://httpbin.org/cookies/delete?foo", handle = h) +req <- curl_fetch_memory("https://hb.r-universe.dev/cookies/delete?foo", handle = h) handle_cookies(h) # Cookies will survive a reset! diff --git a/man/multi.Rd b/man/multi.Rd index 7d4ed9ba..376b8e27 100644 --- a/man/multi.Rd +++ b/man/multi.Rd @@ -105,12 +105,12 @@ failure <- function(str){ cat(paste("Failed request:", str), file = stderr()) } # This handle will take longest (3sec) -h1 <- new_handle(url = "https://eu.httpbin.org/delay/3") +h1 <- new_handle(url = "https://hb.r-universe.dev/delay/3") multi_add(h1, done = success, fail = failure) # This handle writes data to a file con <- file("output.txt") -h2 <- new_handle(url = "https://eu.httpbin.org/post", postfields = "bla bla") +h2 <- new_handle(url = "https://hb.r-universe.dev/post", postfields = "bla bla") multi_add(h2, done = success, fail = failure, data = con) # This handle raises an error diff --git a/man/parse_headers.Rd b/man/parse_headers.Rd index c9839547..ed5b9a07 100644 --- a/man/parse_headers.Rd +++ b/man/parse_headers.Rd @@ -27,7 +27,7 @@ When multiple = TRUE, the function returns a list with the response headers for each request. By default it only returns the headers of the final request. } \examples{ -req <- curl_fetch_memory("https://httpbin.org/redirect/3") +req <- curl_fetch_memory("https://hb.r-universe.dev/redirect/3") parse_headers(req$headers) parse_headers(req$headers, multiple = TRUE) diff --git a/vignettes/intro.Rmd b/vignettes/intro.Rmd index 8628bcfa..6eac900d 100644 --- a/vignettes/intro.Rmd +++ b/vignettes/intro.Rmd @@ -45,7 +45,7 @@ The `curl_fetch_memory` function is a blocking interface which waits for the req ```{r} -req <- curl_fetch_memory("https://eu.httpbin.org/get?foo=123") +req <- curl_fetch_memory("https://hb.r-universe.dev/get?foo=123") str(req) parse_headers(req$headers) jsonlite::prettify(rawToChar(req$content)) @@ -59,7 +59,7 @@ The second method is `curl_download`, which has been designed as a drop-in repla ```{r} tmp <- tempfile() -curl_download("https://eu.httpbin.org/get?bar=456", tmp) +curl_download("https://hb.r-universe.dev/get?bar=456", tmp) jsonlite::prettify(readLines(tmp)) ``` @@ -68,7 +68,7 @@ jsonlite::prettify(readLines(tmp)) The most flexible interface is the `curl` function, which has been designed as a drop-in replacement for base `url`. It will create a so-called connection object, which allows for incremental (asynchronous) reading of the response. ```{r} -con <- curl("https://eu.httpbin.org/get") +con <- curl("https://hb.r-universe.dev/get") open(con) # Get 3 lines @@ -115,7 +115,7 @@ pool <- new_pool() cb <- function(req){cat("done:", req$url, ": HTTP:", req$status, "\n")} curl_fetch_multi('https://www.google.com', done = cb, pool = pool) curl_fetch_multi('https://cloud.r-project.org', done = cb, pool = pool) -curl_fetch_multi('https://httpbin.org/blabla', done = cb, pool = pool) +curl_fetch_multi('https://hb.r-universe.dev/blabla', done = cb, pool = pool) ``` When we call `multi_run()`, all scheduled requests are performed concurrently. The callback functions get triggered when each request completes. @@ -283,14 +283,14 @@ Code that sets `http_version` to `1` (or even `1.1` which R simply rounds to 1) After the handle has been configured, it can be used with any of the download interfaces to perform the request. For example `curl_fetch_memory` will load store the output of the request in memory: ```{r} -req <- curl_fetch_memory("https://eu.httpbin.org/post", handle = h) +req <- curl_fetch_memory("https://hb.r-universe.dev/post", handle = h) jsonlite::prettify(rawToChar(req$content)) ``` Alternatively we can use `curl()` to read the data of via a connection interface: ```{r} -con <- curl("https://eu.httpbin.org/post", handle = h) +con <- curl("https://hb.r-universe.dev/post", handle = h) jsonlite::prettify(readLines(con)) ``` @@ -302,14 +302,14 @@ Or we can use `curl_download` to write the response to disk: ```{r} tmp <- tempfile() -curl_download("https://eu.httpbin.org/post", destfile = tmp, handle = h) +curl_download("https://hb.r-universe.dev/post", destfile = tmp, handle = h) jsonlite::prettify(readLines(tmp)) ``` Or perform the same request with a multi pool: ```{r} -curl_fetch_multi("https://eu.httpbin.org/post", handle = h, done = function(res){ +curl_fetch_multi("https://hb.r-universe.dev/post", handle = h, done = function(res){ cat("Request complete! Response content:\n") cat(rawToChar(res$content)) }) @@ -327,12 +327,12 @@ Curl handles automatically keep track of cookies set by the server. At any given h <- new_handle() # Ask server to set some cookies -req <- curl_fetch_memory("https://eu.httpbin.org/cookies/set?foo=123&bar=ftw", handle = h) -req <- curl_fetch_memory("https://eu.httpbin.org/cookies/set?baz=moooo", handle = h) +req <- curl_fetch_memory("https://hb.r-universe.dev/cookies/set?foo=123&bar=ftw", handle = h) +req <- curl_fetch_memory("https://hb.r-universe.dev/cookies/set?baz=moooo", handle = h) handle_cookies(h) # Unset a cookie -req <- curl_fetch_memory("https://eu.httpbin.org/cookies/delete?foo", handle = h) +req <- curl_fetch_memory("https://hb.r-universe.dev/cookies/delete?foo", handle = h) handle_cookies(h) ``` @@ -345,7 +345,7 @@ In most cases you should not re-use a single handle object for more than one req In recent versions of the curl package there are no performance benefits of reusing handles. The overhead of creating and configuring a new handle object is negligible. The safest way to issue multiple requests, either to a single server or multiple servers is by using a separate handle for each request (which is the default) ```{r} -req1 <- curl_fetch_memory("https://eu.httpbin.org/get") +req1 <- curl_fetch_memory("https://hb.r-universe.dev/get") req2 <- curl_fetch_memory("https://www.r-project.org") ``` @@ -381,7 +381,7 @@ handle_setform(h, description = form_file(system.file("DESCRIPTION")), logo = form_file(file.path(R.home('doc'), "html/logo.jpg"), "image/jpeg") ) -req <- curl_fetch_memory("https://eu.httpbin.org/post", handle = h) +req <- curl_fetch_memory("https://hb.r-universe.dev/post", handle = h) ``` The `form_file` function is used to upload files with the form post. It has two arguments: a file path, and optionally a content-type value. If no content-type is set, curl will guess the content type of the file based on the file extension. @@ -398,6 +398,6 @@ library(magrittr) new_handle() %>% handle_setopt(copypostfields = "moo=moomooo") %>% handle_setheaders("Content-Type"="text/moo", "Cache-Control"="no-cache", "User-Agent"="A cow") %>% - curl_fetch_memory(url = "https://eu.httpbin.org/post") %$% content %>% + curl_fetch_memory(url = "https://hb.r-universe.dev/post") %$% content %>% rawToChar %>% jsonlite::prettify() ```