[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( export async function getJsonActivity(
url: string, 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, timeout = 10000,
headers?: Record<string, string>, headers?: Record<string, string>,
) { ) {
@ -50,8 +50,9 @@ export async function getJsonActivity(
const contentType = res.headers.get('content-type'); const contentType = res.headers.get('content-type');
if (contentType == null || if (contentType == null ||
(contentType !== 'application/activity+json' && !contentType.startsWith('application/activity+json;') && (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}`); throw new Error(`getJsonActivity response had unexpected content-type: ${contentType}`);
}
return { return {
finalUrl: res.url, finalUrl: res.url,

View file

@ -65,7 +65,7 @@ export function createSignedGet(args: {
method: "GET", method: "GET",
headers: objectAssignWithLcKey( 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(), Date: new Date().toUTCString(),
Host: new URL(args.url).hostname, 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'); 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}`); throw new Error(`signedGet response had unexpected content-type: ${contentType}`);
}
return { return {
finalUrl: res.url, finalUrl: res.url,