forked from AkkomaGang/akkoma
Merge pull request 'Use standard-compliant Accept header when fetching' (#740) from Oneric/akkoma:fetch_std-accept-hdr into develop
Reviewed-on: AkkomaGang/akkoma#740
This commit is contained in:
commit
e2e4f53585
2 changed files with 38 additions and 32 deletions
|
@ -324,7 +324,11 @@ def get_object(id) do
|
|||
date = Pleroma.Signature.signed_date()
|
||||
|
||||
headers =
|
||||
[{"accept", "application/activity+json"}]
|
||||
[
|
||||
# The first is required by spec, the second provided as a fallback for buggy implementations
|
||||
{"accept", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""},
|
||||
{"accept", "application/activity+json"}
|
||||
]
|
||||
|> maybe_date_fetch(date)
|
||||
|> sign_fetch(id, date)
|
||||
|
||||
|
|
|
@ -5,7 +5,16 @@
|
|||
defmodule HttpRequestMock do
|
||||
require Logger
|
||||
|
||||
def activitypub_object_headers, do: [{"content-type", "application/activity+json"}]
|
||||
def activitypub_object_headers,
|
||||
do: [
|
||||
{"content-type", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""}
|
||||
]
|
||||
|
||||
# The Accept headers we genrate to be exact; AP spec only requires the first somewhere
|
||||
@activitypub_accept_headers [
|
||||
{"accept", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""},
|
||||
{"accept", "application/activity+json"}
|
||||
]
|
||||
|
||||
def request(
|
||||
%Tesla.Env{
|
||||
|
@ -97,7 +106,7 @@ def get("https://mastodon.sdf.org/users/rinpatch/collections/featured", _, _, _)
|
|||
File.read!("test/fixtures/users_mock/masto_featured.json")
|
||||
|> String.replace("{{domain}}", "mastodon.sdf.org")
|
||||
|> String.replace("{{nickname}}", "rinpatch"),
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
headers: activitypub_object_headers()
|
||||
}}
|
||||
end
|
||||
|
||||
|
@ -208,7 +217,7 @@ def get(
|
|||
"https://mst3k.interlinked.me/users/luciferMysticus",
|
||||
_,
|
||||
_,
|
||||
[{"accept", "application/activity+json"}]
|
||||
@activitypub_accept_headers
|
||||
) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
@ -231,7 +240,7 @@ def get(
|
|||
"https://hubzilla.example.org/channel/kaniini",
|
||||
_,
|
||||
_,
|
||||
[{"accept", "application/activity+json"}]
|
||||
@activitypub_accept_headers
|
||||
) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
@ -241,7 +250,7 @@ def get(
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://niu.moe/users/rye", _, _, [{"accept", "application/activity+json"}]) do
|
||||
def get("https://niu.moe/users/rye", _, _, @activitypub_accept_headers) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
|
@ -250,7 +259,7 @@ def get("https://niu.moe/users/rye", _, _, [{"accept", "application/activity+jso
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://n1u.moe/users/rye", _, _, [{"accept", "application/activity+json"}]) do
|
||||
def get("https://n1u.moe/users/rye", _, _, @activitypub_accept_headers) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
|
@ -270,7 +279,7 @@ def get("http://mastodon.example.org/users/admin/statuses/100787282858396771", _
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://puckipedia.com/", _, _, [{"accept", "application/activity+json"}]) do
|
||||
def get("https://puckipedia.com/", _, _, @activitypub_accept_headers) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
|
@ -342,9 +351,12 @@ def get("https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39", _, _, [
|
||||
{"accept", "application/activity+json"}
|
||||
]) do
|
||||
def get(
|
||||
"https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39",
|
||||
_,
|
||||
_,
|
||||
@activitypub_accept_headers
|
||||
) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
|
@ -353,7 +365,7 @@ def get("https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39", _,
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://mobilizon.org/@tcit", _, _, [{"accept", "application/activity+json"}]) do
|
||||
def get("https://mobilizon.org/@tcit", _, _, @activitypub_accept_headers) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
|
@ -416,9 +428,7 @@ def get(
|
|||
{:ok, %Tesla.Env{status: 404, body: ""}}
|
||||
end
|
||||
|
||||
def get("http://mastodon.example.org/users/relay", _, _, [
|
||||
{"accept", "application/activity+json"}
|
||||
]) do
|
||||
def get("http://mastodon.example.org/users/relay", _, _, @activitypub_accept_headers) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
|
@ -427,9 +437,7 @@ def get("http://mastodon.example.org/users/relay", _, _, [
|
|||
}}
|
||||
end
|
||||
|
||||
def get("http://mastodon.example.org/users/gargron", _, _, [
|
||||
{"accept", "application/activity+json"}
|
||||
]) do
|
||||
def get("http://mastodon.example.org/users/gargron", _, _, @activitypub_accept_headers) do
|
||||
{:error, :nxdomain}
|
||||
end
|
||||
|
||||
|
@ -620,7 +628,7 @@ def get("https://shitposter.club/notice/7369654", _, _, _) do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://mstdn.io/users/mayuutann", _, _, [{"accept", "application/activity+json"}]) do
|
||||
def get("https://mstdn.io/users/mayuutann", _, _, @activitypub_accept_headers) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
|
@ -633,7 +641,7 @@ def get(
|
|||
"https://mstdn.io/users/mayuutann/statuses/99568293732299394",
|
||||
_,
|
||||
_,
|
||||
[{"accept", "application/activity+json"}]
|
||||
@activitypub_accept_headers
|
||||
) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
@ -779,7 +787,7 @@ def get(
|
|||
"http://gs.example.org:4040/index.php/user/1",
|
||||
_,
|
||||
_,
|
||||
[{"accept", "application/activity+json"}]
|
||||
@activitypub_accept_headers
|
||||
) do
|
||||
{:ok, %Tesla.Env{status: 406, body: ""}}
|
||||
end
|
||||
|
@ -966,7 +974,7 @@ def get("https://apfed.club/channel/indio", _, _, _) do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://social.heldscal.la/user/23211", _, _, [{"accept", "application/activity+json"}]) do
|
||||
def get("https://social.heldscal.la/user/23211", _, _, @activitypub_accept_headers) do
|
||||
{:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
|
||||
end
|
||||
|
||||
|
@ -1207,13 +1215,11 @@ def get("https://lm.kazv.moe/users/mewmew/collections/featured", _, _, _) do
|
|||
File.read!("test/fixtures/users_mock/masto_featured.json")
|
||||
|> String.replace("{{domain}}", "lm.kazv.moe")
|
||||
|> String.replace("{{nickname}}", "mewmew"),
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
headers: activitypub_object_headers()
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://info.pleroma.site/activity.json", _, _, [
|
||||
{"accept", "application/activity+json"}
|
||||
]) do
|
||||
def get("https://info.pleroma.site/activity.json", _, _, @activitypub_accept_headers) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
|
@ -1226,9 +1232,7 @@ def get("https://info.pleroma.site/activity.json", _, _, _) do
|
|||
{:ok, %Tesla.Env{status: 404, body: ""}}
|
||||
end
|
||||
|
||||
def get("https://info.pleroma.site/activity2.json", _, _, [
|
||||
{"accept", "application/activity+json"}
|
||||
]) do
|
||||
def get("https://info.pleroma.site/activity2.json", _, _, @activitypub_accept_headers) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
|
@ -1241,9 +1245,7 @@ def get("https://info.pleroma.site/activity2.json", _, _, _) do
|
|||
{:ok, %Tesla.Env{status: 404, body: ""}}
|
||||
end
|
||||
|
||||
def get("https://info.pleroma.site/activity3.json", _, _, [
|
||||
{"accept", "application/activity+json"}
|
||||
]) do
|
||||
def get("https://info.pleroma.site/activity3.json", _, _, @activitypub_accept_headers) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
|
|
Loading…
Reference in a new issue