getkirby-v2/toolkit

Link-header gets overwritten by two values

sebsel opened this issue · 3 comments

This URL has two Link-headers, and I am interested in the first: https://www.svenknebel.de/posts/2017/5/13/

HTTP/1.1 401 UNAUTHORIZED
Server: nginx/1.9.10
Date: Sun, 21 May 2017 15:49:14 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 13
Connection: close
Link: <https://www.svenknebel.de/post_token>; rel="token_endpoint"
Link: </webmention>; rel="webmention"
WWW-Authenticate: Bearer

auth required

The remote::head() overwrites the Link header when it sees a second one.

  ["headers"]=>
  array(7) {
    ["Server"]=>
    string(12) "nginx/1.9.10"
    ["Date"]=>
    string(29) "Sun, 21 May 2017 16:17:00 GMT"
    ["Content-Type"]=>
    string(24) "text/html; charset=utf-8"
    ["Content-Length"]=>
    string(2) "13"
    ["Connection"]=>
    string(10) "keep-alive"
    ["Link"]=>
    string(31) "</webmention>; rel="webmention""
    ["WWW-Authenticate"]=>
    string(6) "Bearer"
  }

This is a common problem when parsing HTTP Link headers. Feel free to use this code or test cases: https://github.com/indieweb/link-rel-parser-php

You are right, that's a bug. What do you think: Should we return an array of Link headers in that case?

Also, thanks Aaron for the link.

Fixed by #237. But this will be in 2.5 as it's a breaking change.