File: headers.R

package info (click to toggle)
r-cran-crul 1.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,620 kB
  • sloc: sh: 13; makefile: 2
file content (16 lines) | stat: -rw-r--r-- 499 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
head_parse <- function(z) {
  status <- list(status = sw(z[[1]]))
  hl <- z[z != ""][-1]
  ff <- regexec("^([^:]*):\\s*(.*)$", hl)
  xx <- regmatches(hl, ff)
  n <- vapply(xx, length, integer(1))
  if (any(n != 3)) {
    bad <- hl[n != 3]
    xx <- xx[n == 3]
    warning("Failed to parse headers:\n", paste0(bad, "\n"),
      call. = FALSE)
  }
  names <- tolower(vapply(xx, "[[", 2, FUN.VALUE = character(1)))
  values <- lapply(xx, "[[", 3)
  c(status, as.list(stats::setNames(values, names)))
}