diff --git a/NEWS.md b/NEWS.md index f09f990e..7d228417 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # httr2 (development version) +* `resp_link_url()` now works if there are multiple `Link` headers (#587). * `url_parse()` now uses `curl::curl_parse_url()` which is much faster and more correct (#577). * `req_retry()` now defaults to `max_tries = 2` with a message. Set to `max_tries = 1` to disable retries. diff --git a/R/resp-headers.R b/R/resp-headers.R index 0560fc33..d76f18bb 100644 --- a/R/resp-headers.R +++ b/R/resp-headers.R @@ -173,7 +173,9 @@ resp_link_url <- function(resp, rel) { return() } - links <- parse_link(resp_header(resp, "Link")) + headers <- resp_headers(resp) + link_headers <- headers[names(headers) == "Link"] + links <- unlist(lapply(link_headers, parse_link), recursive = FALSE) sel <- map_lgl(links, ~ .$rel == rel) if (sum(sel) != 1L) { return() diff --git a/man/oauth_token_cached.Rd b/man/oauth_token_cached.Rd index 123fe5ee..bb2fa767 100644 --- a/man/oauth_token_cached.Rd +++ b/man/oauth_token_cached.Rd @@ -40,17 +40,4 @@ manual token management that still takes advantage of httr2's caching system. You should only need to use this function if you're passing the token } -\examples{ -\dontrun{ -token <- oauth_token_cached( - client = example_github_client(), - flow = oauth_flow_auth_code, - flow_params = list( - auth_url = "https://github.com/login/oauth/authorize" - ), - cache_disk = TRUE -) -token -} -} \keyword{internal} diff --git a/tests/testthat/test-resp-headers.R b/tests/testthat/test-resp-headers.R index 52c9c42e..cfc3070f 100644 --- a/tests/testthat/test-resp-headers.R +++ b/tests/testthat/test-resp-headers.R @@ -58,3 +58,12 @@ test_that("can extract specified link url", { expect_equal(resp_link_url(resp, "first"), NULL) expect_equal(resp_link_url(response(), "first"), NULL) }) + +test_that("can extract from multiple link headers", { + resp <- response(headers = c( + 'Link: ; rel="next"', + 'Link: ; rel="last"' + )) + expect_equal(resp_link_url(resp, "next"), "https://example.com/1") + expect_equal(resp_link_url(resp, "last"), "https://example.com/2") +})