Add Content-Type and User-Agent for activity delivery

This commit is contained in:
noellabo 2022-05-02 23:36:12 +09:00
parent 8ac4e72e65
commit 74cc41d4fa
9 changed files with 55 additions and 9 deletions

View file

@ -63,7 +63,12 @@ class FanoutDeletePipeline implements ShouldQueue
$requests = function($audience) use ($client, $activity, $profile, $payload) { $requests = function($audience) use ($client, $activity, $profile, $payload) {
foreach($audience as $url) { foreach($audience as $url) {
$headers = HttpSignature::sign($profile, $url, $activity); $version = config('pixelfed.version');
$appUrl = config('app.url');
$headers = HttpSignature::sign($profile, $url, $activity, [
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})",
]);
yield function() use ($client, $url, $headers, $payload) { yield function() use ($client, $url, $headers, $payload) {
return $client->postAsync($url, [ return $client->postAsync($url, [
'curl' => [ 'curl' => [

View file

@ -129,7 +129,12 @@ class SharePipeline implements ShouldQueue
$requests = function($audience) use ($client, $activity, $profile, $payload) { $requests = function($audience) use ($client, $activity, $profile, $payload) {
foreach($audience as $url) { foreach($audience as $url) {
$headers = HttpSignature::sign($profile, $url, $activity); $version = config('pixelfed.version');
$appUrl = config('app.url');
$headers = HttpSignature::sign($profile, $url, $activity, [
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})",
]);
yield function() use ($client, $url, $headers, $payload) { yield function() use ($client, $url, $headers, $payload) {
return $client->postAsync($url, [ return $client->postAsync($url, [
'curl' => [ 'curl' => [

View file

@ -92,7 +92,12 @@ class UndoSharePipeline implements ShouldQueue
$requests = function($audience) use ($client, $activity, $profile, $payload) { $requests = function($audience) use ($client, $activity, $profile, $payload) {
foreach($audience as $url) { foreach($audience as $url) {
$headers = HttpSignature::sign($profile, $url, $activity); $version = config('pixelfed.version');
$appUrl = config('app.url');
$headers = HttpSignature::sign($profile, $url, $activity, [
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})",
]);
yield function() use ($client, $url, $headers, $payload) { yield function() use ($client, $url, $headers, $payload) {
return $client->postAsync($url, [ return $client->postAsync($url, [
'curl' => [ 'curl' => [

View file

@ -87,7 +87,12 @@ class StatusActivityPubDeliver implements ShouldQueue
$requests = function($audience) use ($client, $activity, $profile, $payload) { $requests = function($audience) use ($client, $activity, $profile, $payload) {
foreach($audience as $url) { foreach($audience as $url) {
$headers = HttpSignature::sign($profile, $url, $activity); $version = config('pixelfed.version');
$appUrl = config('app.url');
$headers = HttpSignature::sign($profile, $url, $activity, [
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})",
]);
yield function() use ($client, $url, $headers, $payload) { yield function() use ($client, $url, $headers, $payload) {
return $client->postAsync($url, [ return $client->postAsync($url, [
'curl' => [ 'curl' => [

View file

@ -144,7 +144,12 @@ class StatusDelete implements ShouldQueue
$requests = function($audience) use ($client, $activity, $profile, $payload) { $requests = function($audience) use ($client, $activity, $profile, $payload) {
foreach($audience as $url) { foreach($audience as $url) {
$headers = HttpSignature::sign($profile, $url, $activity); $version = config('pixelfed.version');
$appUrl = config('app.url');
$headers = HttpSignature::sign($profile, $url, $activity, [
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})",
]);
yield function() use ($client, $url, $headers, $payload) { yield function() use ($client, $url, $headers, $payload) {
return $client->postAsync($url, [ return $client->postAsync($url, [
'curl' => [ 'curl' => [

View file

@ -108,7 +108,12 @@ class StoryDelete implements ShouldQueue
$requests = function($audience) use ($client, $activity, $profile, $payload) { $requests = function($audience) use ($client, $activity, $profile, $payload) {
foreach($audience as $url) { foreach($audience as $url) {
$headers = HttpSignature::sign($profile, $url, $activity); $version = config('pixelfed.version');
$appUrl = config('app.url');
$headers = HttpSignature::sign($profile, $url, $activity, [
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})",
]);
yield function() use ($client, $url, $headers, $payload) { yield function() use ($client, $url, $headers, $payload) {
return $client->postAsync($url, [ return $client->postAsync($url, [
'curl' => [ 'curl' => [

View file

@ -125,7 +125,12 @@ class StoryExpire implements ShouldQueue
$requests = function($audience) use ($client, $activity, $profile, $payload) { $requests = function($audience) use ($client, $activity, $profile, $payload) {
foreach($audience as $url) { foreach($audience as $url) {
$headers = HttpSignature::sign($profile, $url, $activity); $version = config('pixelfed.version');
$appUrl = config('app.url');
$headers = HttpSignature::sign($profile, $url, $activity, [
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})",
]);
yield function() use ($client, $url, $headers, $payload) { yield function() use ($client, $url, $headers, $payload) {
return $client->postAsync($url, [ return $client->postAsync($url, [
'curl' => [ 'curl' => [

View file

@ -79,7 +79,13 @@ class StoryFanout implements ShouldQueue
$requests = function($audience) use ($client, $activity, $profile, $payload) { $requests = function($audience) use ($client, $activity, $profile, $payload) {
foreach($audience as $url) { foreach($audience as $url) {
$headers = HttpSignature::sign($profile, $url, $activity); $version = config('pixelfed.version');
$appUrl = config('app.url');
$proxy = config('');
$headers = HttpSignature::sign($profile, $url, $activity, [
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})",
]);
yield function() use ($client, $url, $headers, $payload) { yield function() use ($client, $url, $headers, $payload) {
return $client->postAsync($url, [ return $client->postAsync($url, [
'curl' => [ 'curl' => [

View file

@ -49,7 +49,12 @@ class ActivityPubDeliveryService
$body = $this->payload; $body = $this->payload;
$payload = json_encode($body); $payload = json_encode($body);
$headers = HttpSignature::sign($this->sender, $this->to, $body); $version = config('pixelfed.version');
$appUrl = config('app.url');
$headers = HttpSignature::sign($this->sender, $this->to, $body, [
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})",
]);
$ch = curl_init($this->to); $ch = curl_init($this->to);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);