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

More lenient HTTP Link Header parsing, for different HTTP server compatibility #166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading