Skip to content

Commit

Permalink
Switch to self hosted httpbin
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Jun 6, 2023
1 parent ddc2cd1 commit 9499b9f
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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")'
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions R/curl.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion R/echo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
#'
Expand Down
13 changes: 8 additions & 5 deletions R/fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
#' })
#'
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions R/handle.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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!
Expand Down
4 changes: 2 additions & 2 deletions R/multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/parse_headers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#'
Expand Down
16 changes: 8 additions & 8 deletions man/curl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/curl_echo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions man/curl_fetch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/handle.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/handle_cookies.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/multi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/parse_headers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9499b9f

Please sign in to comment.