Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resp_link_url() doesn't handle multiple link headers #587

Open
maarten-vermeyen opened this issue Nov 22, 2024 · 0 comments
Open

resp_link_url() doesn't handle multiple link headers #587

maarten-vermeyen opened this issue Nov 22, 2024 · 0 comments

Comments

@maarten-vermeyen
Copy link

Hi everyone,

I came upon an issue with responses with multiple link headers in the response. While this is allowed by RFC 8288 (https://www.rfc-editor.org/rfc/rfc8288.html, see examples at bottom of section 3.5), the call to resp_link_url() and the underlying call to resp_header() only returns the value of the first header.

Example:

library(httr2)

# example request
resp <- request("https://geo.api.vlaanderen.be/Gebouwenregister") |>
          req_url_path_append("ogc/features/v1/collections/Gebouw/items") |>
          req_url_query(limit=50, 
                        crs="http://www.opengis.net/def/crs/EPSG/0/31370",
                        startIndex=50) |>
          req_headers(Accept = "application/geo+json") |>
          req_perform()

# headers contain multiple links
print(resp_headers(resp))

# resp_link_url() will return NULL for rel "next"
print(resp_link_url(resp, rel="next")

# resp_header("link") returns only the first value
print(resp_header(resp, "link")

Output:

<httr2_headers>
date: Fri, 22 Nov 2024 21:14:48 GMT
content-type: application/geo+json
x-ms-middleware-request-id: 00000000-0000-0000-0000-000000000000
x-content-type-options: nosniff
link: <https://geo.api.vlaanderen.be/Gebouwenregister/ogc/features/v1/collections/Gebouw/items?limit=50&crs=http%3A%2F%2Fwww.opengis.net%2Fdef%2Fcrs%2FEPSG%2F0%2F31370&startIndex=0>; rel="prev"; type="application/geo+json"
link: <https://geo.api.vlaanderen.be/Gebouwenregister/ogc/features/v1/collections/Gebouw/items?limit=50&crs=http%3A%2F%2Fwww.opengis.net%2Fdef%2Fcrs%2FEPSG%2F0%2F31370&startIndex=100>; rel="next"; type="application/geo+json"
content-crs: <http://www.opengis.net/def/crs/EPSG/0/31370>
api-version: 1.0.1
content-disposition: inline; filename=Gebouw.json
access-control-allow-origin: *
x-robots-tag: all
NULL
[1] "<https://geo.api.vlaanderen.be/Gebouwenregister/ogc/features/v1/collections/Gebouw/items?limit=50&crs=http%3A%2F%2Fwww.opengis.net%2Fdef%2Fcrs%2FEPSG%2F0%2F31370&startIndex=0>; rel=\"prev\"; type=\"application/geo+json\""

I'm not sure what would be the optimal solution for this problem. I think the easiest would be to adapt the function resp_link_url() to use resp_headers(resp, filter='link') and than handle each link header, instead of using resp_header('link').

Kind regards,

Maarten

@maarten-vermeyen maarten-vermeyen changed the title resp_link_url() and doesn't handle multiple link headers resp_link_url() doesn't handle multiple link headers Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant