Skip to contents

Convenience wrapper around !httr::http_error() that returns

Usage

is_http_success(url, retries = 0L, quiet = TRUE)

Arguments

url

HTTP protocol address. The scheme is optional, so both "google.com" and "https://google.com" will work. A character scalar.

retries

Maximum number of retries of the HEAD request in case of an HTTP error. An integer scalar >= 0. The retries are performed using exponential backoff and jitter, see httr::RETRY() for details.

quiet

Whether or not to suppress the message displaying how long until the next retry in case an HTTP error occurred. A logical scalar. Only relevant if retries > 0.

Value

A logical scalar.

Details

This function is similar to RCurl::url.exists(), i.e. it only retrieves the header, no body, but is based on httr which in turn is based on curl.

For checks on lower levels of the network stack like performing DNS queries or TCP port pings, see the pingr package.

See also

Other HTTP functions: assert_mime_type(), is_url(), req_cached()

Examples

pal::is_http_success("goo.gl")
#> [1] TRUE
pal::is_http_success("https://google.com/")
#> [1] TRUE
pal::is_http_success("https://google.not/")
#> [1] FALSE
pal::is_http_success("https://google.not/",
                     retries = 2,
                     quiet = FALSE)
#> Error in curl::curl_fetch_memory(url, handle = handle): Could not resolve host: google.not
#> Request failed [ERROR]. Retrying in 1.7 seconds...
#> Error in curl::curl_fetch_memory(url, handle = handle): Could not resolve host: google.not
#> Request failed [ERROR]. Retrying in 3 seconds...
#> [1] FALSE