File tree Expand file tree Collapse file tree 3 files changed +13
-1
lines changed
Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 11# httr2 (development version)
22
3+ * ` resp_link_url() ` now works if there are multiple ` Link ` headers (#587 ).
34* New ` url_modify() ` makes it easier to modify an existing url (#464 ).
45* New ` req_url_relative() ` for constructing relative urls (#449 ).
56* ` url_parse() ` gains ` base_url ` argument so you can also use it to parse relative URLs (#449 ).
Original file line number Diff line number Diff line change @@ -173,7 +173,9 @@ resp_link_url <- function(resp, rel) {
173173 return ()
174174 }
175175
176- links <- parse_link(resp_header(resp , " Link" ))
176+ headers <- resp_headers(resp )
177+ link_headers <- headers [names(headers ) == " Link" ]
178+ links <- unlist(lapply(link_headers , parse_link ), recursive = FALSE )
177179 sel <- map_lgl(links , ~ . $ rel == rel )
178180 if (sum(sel ) != 1L ) {
179181 return ()
Original file line number Diff line number Diff line change @@ -58,3 +58,12 @@ test_that("can extract specified link url", {
5858 expect_equal(resp_link_url(resp , " first" ), NULL )
5959 expect_equal(resp_link_url(response(), " first" ), NULL )
6060})
61+
62+ test_that(" can extract from multiple link headers" , {
63+ resp <- response(headers = c(
64+ ' Link: <https://example.com/1>; rel="next"' ,
65+ ' Link: <https://example.com/2>; rel="last"'
66+ ))
67+ expect_equal(resp_link_url(resp , " next" ), " https://example.com/1" )
68+ expect_equal(resp_link_url(resp , " last" ), " https://example.com/2" )
69+ })
You can’t perform that action at this time.
0 commit comments