Skip to content

Commit

Permalink
HTTP Link Headers my be separated by comma-space or simply comma.
Browse files Browse the repository at this point in the history
Similarly, link attrs may be sepatated by semicolon-space, or just semicolon.
  • Loading branch information
ashleysommer committed Jun 24, 2024
1 parent 067ab41 commit 3d4f6fa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/composables/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class NetworkError extends Error {
* @returns
*/
function parseLinkHeader(link: string): LinkObject {
const [, uriRef, attrs] = link.match(/<(.+)>; (.+)/)!;
const [, uriRef, attrs] = link.match(/<(.+)>;\s?(.+)/)!;
let linkObj: Partial<LinkObject> = { uriRef };

attrs.split("; ").forEach(l => {
const [, lhs, rhs] = l.match(/(.+)=[\"<](.+)[\">]/) as [string, keyof Omit<LinkObject, "uriRef">, string];
attrs.split(";").forEach(l => {
const [, lhs, rhs] = l.trim().match(/(.+)=[\"<](.+)[\">]/) as [string, keyof Omit<LinkObject, "uriRef">, string];
linkObj[lhs] = rhs;
});

Expand Down Expand Up @@ -60,7 +60,7 @@ async function individualApiRequest(url: string) {
function getProfilesFromHeaders(link: string): ProfileHeader[] {
let profileObj: {[uri: string]: ProfileHeader} = {} ;

const links = link.split(", ").map(l => parseLinkHeader(l));
const links = link.split(",").map(l => parseLinkHeader(l.trim()));

links.filter(l => l.rel === "type").forEach(l => {
profileObj[l.anchor] = {
Expand Down

0 comments on commit 3d4f6fa

Please sign in to comment.