Skip to content

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

Closed
@maarten-vermeyen

Description

@maarten-vermeyen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions