delivery user-agent and accept header

refs https://github.com/cloudflare/wildebeest/issues/80
pull/203/head
Sven Sauleau 2023-02-06 16:55:35 +00:00
rodzic aac4d74c8b
commit 67f76d2a19
4 zmienionych plików z 12 dodań i 30 usunięć

Wyświetl plik

@ -7,12 +7,14 @@ import type { Actor } from './actors'
import { generateDigestHeader } from 'wildebeest/backend/src/utils/http-signing-cavage'
import { signRequest } from 'wildebeest/backend/src/utils/http-signing'
import { getFollowers } from 'wildebeest/backend/src/mastodon/follow'
const headers = {
'content-type': 'application/activity+json',
}
import { WILDEBEEST_VERSION, MASTODON_API_VERSION } from 'wildebeest/config/versions'
export async function deliverToActor(signingKey: CryptoKey, from: Actor, to: Actor, activity: Activity) {
const headers = {
Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'User-Agent': `Wildebeest/${WILDEBEEST_VERSION} Mastodon/${MASTODON_API_VERSION}`,
}
const body = JSON.stringify(activity)
console.log({ body })
const req = new Request(to.inbox, {
@ -29,10 +31,7 @@ export async function deliverToActor(signingKey: CryptoKey, from: Actor, to: Act
const body = await res.text()
throw new Error(`delivery to ${to.inbox} returned ${res.status}: ${body}`)
}
{
const body = await res.text()
console.log(`${to.inbox} returned 200: ${body}`)
}
console.log(`${to.inbox} returned 200`)
}
export async function deliverFollowers(

Wyświetl plik

@ -1,7 +1,7 @@
import * as packagejson from '../package.json'
// https://github.com/mastodon/mastodon/blob/main/CHANGELOG.md
const MASTODON_API_VERSION = '4.0.2'
export const MASTODON_API_VERSION = '4.0.2'
export const WILDEBEEST_VERSION = packagejson.version

Wyświetl plik

@ -5,6 +5,7 @@ import type { Actor } from 'wildebeest/backend/src/activitypub/actors'
import type { Env } from './'
import { generateDigestHeader } from 'wildebeest/backend/src/utils/http-signing-cavage'
import { signRequest } from 'wildebeest/backend/src/utils/http-signing'
import { deliverToActor } from 'wildebeest/backend/src/activitypub/deliver'
const headers = {
'content-type': 'application/activity+json',
@ -18,26 +19,6 @@ export async function handleDeliverMessage(env: Env, actor: Actor, message: Deli
return
}
const body = JSON.stringify(message.activity)
const req = new Request(targetActor.inbox, {
method: 'POST',
body,
headers,
})
const digest = await generateDigestHeader(body)
req.headers.set('Digest', digest)
const signingKey = await getSigningKey(message.userKEK, env.DATABASE, actor)
await signRequest(req, signingKey, actor.id)
const res = await fetch(req)
if (!res.ok) {
const body = await res.text()
console.error(`delivery to ${targetActor.inbox} returned ${res.status}: ${body}`)
return
}
{
const body = await res.text()
console.log(`${targetActor.inbox} returned 200: ${body}`)
}
await deliverToActor(signingKey, actor, targetActor, message.activity)
}

Wyświetl plik

@ -29,6 +29,8 @@ describe('Consumer', () => {
}
if (input.url.toString() === 'https://example.com/inbox') {
assert(input.headers.get('accept').includes('json'))
assert(input.headers.get('user-agent').includes('Wildebeest'))
assert.equal(input.method, 'POST')
receivedActivity = await input.json()
return new Response('')