| 1 |
cat("This is libcurl version", curl_version()$version, "with", curl_version()$ssl_version, "\n") |
| 2 |
|
| 3 |
# Try to load test server |
| 4 |
find_test_server <- function(){ |
| 5 |
h <- new_handle(timeout = 10, failonerror = TRUE) |
| 6 |
|
| 7 |
# Try to download latest test-server list |
| 8 |
servers <- tryCatch({ |
| 9 |
con <- curl("https://jeroen.github.io/curl/servers.R", handle = h) |
| 10 |
on.exit(close(con)) |
| 11 |
out <- source(con, local = TRUE) |
| 12 |
out$value |
| 13 |
}, error = function(e){ |
| 14 |
message("Failed to download server list:", e$message) |
| 15 |
c("https://eu.httpbin.org", "https://httpbin.org", "http://httpbin.org") |
| 16 |
}) |
| 17 |
|
| 18 |
|
| 19 |
# Try each test-server in the list |
| 20 |
for(host in servers){ |
| 21 |
tryCatch({ |
| 22 |
url <- paste0(host, "/get") |
| 23 |
req <- curl_fetch_memory(url, handle = h) |
| 24 |
return(host) |
| 25 |
}, error = function(e){ |
| 26 |
message(paste0("Not using ", host, ": ", e$message)) |
| 27 |
}) |
| 28 |
} |
| 29 |
|
| 30 |
stop("All testing servers seem unavailable. No internet connection?") |
| 31 |
} |
| 32 |
|
| 33 |
testserver <- Sys.getenv("HTTPBIN_TEST_SERVER", find_test_server()) |
| 34 |
cat("Using test server:", testserver, "\n") |
| 35 |
|
| 36 |
httpbin <- function(path){ |
| 37 |
paste0(testserver, "/", sub("^/", "", path)) |
| 38 |
} |