-
Notifications
You must be signed in to change notification settings - Fork 2k
/
test-header.r
67 lines (54 loc) · 2.07 KB
/
test-header.r
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
context("Headers")
# Setting ---------------------------------------------------------------------
test_that("Only last duplicated header kept in add_headers", {
expect_equal(add_headers(x = 1, x = 2)$headers, c(x = "2"))
})
test_that("Only last duplicated header kept when combined", {
out <- c(add_headers(x = 1), add_headers(x = 2))
expect_equal(out$headers, c(x = "2"))
})
# Getting ---------------------------------------------------------------------
test_that("All headers captures headers from redirects", {
skip("Currently broken")
r1 <- GET("https://httpbin.org/redirect/1")
expect_equal(length(r1$all_headers), 1 + 1)
r3 <- GET("https://httpbin.org/redirect/3")
expect_equal(length(r3$all_headers), 3 + 1)
})
# Parsing ---------------------------------------------------------------------
test_that("Trailing line breaks removed", {
header <- charToRaw("HTTP/1.1 200 OK\r\nA: B\r\n")
expect_equal(parse_http_headers(header)[[1]]$headers$A, "B")
})
test_that("Invalid header raises error", {
lines <- c(
"HTTP/1.1 200 OK",
"A: B",
"Invalid"
)
header <- charToRaw(paste(lines, collapse = "\n"))
expect_warning(parse_http_headers(header), "Failed to parse headers")
})
test_that("http status line only needs two components", {
headers <- parse_http_headers(charToRaw("HTTP/1.1 200"))
expect_equal(headers[[1]]$status, 200L)
})
test_that("Key/value parsing tolerates multiple ':'", {
lines <- c(
"HTTP/1.1 200 OK",
"A: B:C",
"D:E:F"
)
header <- charToRaw(paste(lines, collapse = "\n"))
expect_equal(parse_http_headers(header)[[1]]$headers$A, "B:C")
expect_equal(parse_http_headers(header)[[1]]$headers$D, "E:F")
})
test_that("cache_info() handles flagless cache control", {
response <- list(flags = "private", `max-age` = "0", `max-stale` = "0")
expect_equal(response[1], parse_cache_control("private"))
expect_equal(response[2], parse_cache_control("max-age=0"))
expect_equal(response[1:2], parse_cache_control("private, max-age=0"))
expect_equal(
response, parse_cache_control("private, max-age=0, max-stale=0")
)
})