Skip to content

Commit 99d4257

Browse files
authored
Make resp_link_url() case-insensitive (#655)
Fixes #654
1 parent d8f20db commit 99d4257

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# httr2 (development version)
22

3+
* `resp_link_url()` once again ignores the case of headers (@DavidRLovell, #655)
34
* `oauth_client()` and `oauth_token()` gain refreshed print methods that use bulleted lists, like other httr2 objects. Additionally, print a `oauth_client()` with a custom `auth` function no longer errors (#648).
45
* `req_headers()` always redacts `Authorization` (#649).
56
* `req_headers_redacted()` supports dynamic dots (#647)

R/resp-headers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ resp_link_url <- function(resp, rel) {
174174
}
175175

176176
headers <- resp_headers(resp)
177-
link_headers <- headers[names(headers) == "Link"]
177+
link_headers <- headers[tolower(names(headers)) == "link"]
178178
links <- unlist(lapply(link_headers, parse_link), recursive = FALSE)
179179
sel <- map_lgl(links, ~ .$rel == rel)
180180
if (sum(sel) != 1L) {

tests/testthat/test-resp-headers.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ test_that("can parse both forms of retry-after header", {
4646
expect_equal(resp_retry_after(resp_rel), NA)
4747
})
4848

49+
# resp_link_url() --------------------------------------------------------------
50+
4951
test_that("can extract specified link url", {
5052
resp <- response(headers = paste0(
5153
'Link: <https://example.com/1>; rel="next",',
@@ -67,3 +69,8 @@ test_that("can extract from multiple link headers", {
6769
expect_equal(resp_link_url(resp, "next"), "https://example.com/1")
6870
expect_equal(resp_link_url(resp, "last"), "https://example.com/2")
6971
})
72+
73+
test_that("is case insensitive", {
74+
resp <- response(headers = 'LINK: <https://example.com/1>; rel="next"')
75+
expect_equal(resp_link_url(resp, "next"), "https://example.com/1")
76+
})

0 commit comments

Comments
 (0)