[backend] When fetching activities, specify the acceptable JSON-LD profile explicitly

This commit is contained in:
Laura Hausmann 2024-02-17 16:11:23 +01:00
parent 099ba9ce65
commit e2cff0340f
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
3 changed files with 8 additions and 4 deletions

View File

@ -30,7 +30,7 @@ export async function getJson(
export async function getJsonActivity(
url: string,
accept = "application/activity+json, application/ld+json",
accept = "application/activity+json, application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
timeout = 10000,
headers?: Record<string, string>,
) {
@ -50,8 +50,9 @@ export async function getJsonActivity(
const contentType = res.headers.get('content-type');
if (contentType == null ||
(contentType !== 'application/activity+json' && !contentType.startsWith('application/activity+json;') &&
(!contentType.startsWith('application/ld+json;') || !contentType.includes('profile="https://www.w3.org/ns/activitystreams"'))))
(!contentType.startsWith('application/ld+json;') || !contentType.includes('profile="https://www.w3.org/ns/activitystreams"')))) {
throw new Error(`getJsonActivity response had unexpected content-type: ${contentType}`);
}
return {
finalUrl: res.url,

View File

@ -65,7 +65,7 @@ export function createSignedGet(args: {
method: "GET",
headers: objectAssignWithLcKey(
{
Accept: "application/activity+json, application/ld+json",
Accept: "application/activity+json, application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
Date: new Date().toUTCString(),
Host: new URL(args.url).hostname,
},

View File

@ -66,8 +66,11 @@ export async function signedGet(url: string, user: { id: User["id"] }, redirects
}
const contentType = res.headers.get('content-type');
if (contentType == null || (contentType !== 'application/activity+json' && !contentType.startsWith('application/activity+json;') && contentType !== 'application/ld+json' && !contentType.startsWith('application/ld+json;')))
if (contentType == null ||
(contentType !== 'application/activity+json' && !contentType.startsWith('application/activity+json;') &&
(!contentType.startsWith('application/ld+json;') || !contentType.includes('profile="https://www.w3.org/ns/activitystreams"')))) {
throw new Error(`signedGet response had unexpected content-type: ${contentType}`);
}
return {
finalUrl: res.url,