File: http.R

package info (click to toggle)
r-cran-pingr 2.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 224 kB
  • sloc: ansic: 649; sh: 69; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 762 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

http_get <- function(url) {
  tmp <- tempfile()
  on.exit(unlink(tmp, recursive = TRUE), add = TRUE)

  suppressWarnings(utils::download.file(url, tmp, quiet = TRUE))

  if (!file.exists(tmp)) stop("Cannot download `", url, "`")

  readChar(tmp, file.info(tmp)$size, useBytes = TRUE)
}

#' Download Apple's captive portal test
#'
#' If the test page, returns "Success" that means that the computer is
#' connected to the Internet.
#'
#' Note that this function will fail if the computer is offline. Use
#' [is_online()] to check if the computer is online.
#'
#' @export
#' @examplesIf pingr:::safe_examples()
#' apple_captive_test()

apple_captive_test <- function() {
  out <- http_get("http://captive.apple.com/hotspot-detect.html")
  grepl("Success", out)
}