changeset 4109:7067b0d73183

component AP gateway: fix AP media type in GET and POST requests headers
author Goffi <goffi@goffi.org>
date Thu, 06 Jul 2023 11:34:52 +0200 (17 months ago)
parents 238e305f2306
children b274f0d5c138
files libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py libervia/backend/plugins/plugin_comp_ap_gateway/constants.py libervia/backend/plugins/plugin_comp_ap_gateway/http_server.py
diffstat 3 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py	Thu Jul 06 11:34:51 2023 +0200
+++ b/libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py	Thu Jul 06 11:34:52 2023 +0200
@@ -377,7 +377,6 @@
             url,
             headers = {
                 "Accept": [MEDIA_TYPE_AP],
-                "Content-Type": [MEDIA_TYPE_AP],
             }
         )
         if resp.code >= 300:
@@ -1345,7 +1344,7 @@
             "Digest": digest
         }
         headers["Content-Type"] = (
-            'application/activity+json'
+            MEDIA_TYPE_AP
         )
         headers, __ = self.get_signature_data(self.get_key_id(actor_id), headers)
 
--- a/libervia/backend/plugins/plugin_comp_ap_gateway/constants.py	Thu Jul 06 11:34:51 2023 +0200
+++ b/libervia/backend/plugins/plugin_comp_ap_gateway/constants.py	Thu Jul 06 11:34:52 2023 +0200
@@ -35,7 +35,8 @@
 TYPE_EVENT = "Event"
 TYPE_JOIN = "Join"
 TYPE_LEAVE = "Leave"
-MEDIA_TYPE_AP = "application/activity+json"
+MEDIA_TYPE_AP = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
+MEDIA_TYPE_AP_ALT = "application/activity+json"
 NS_AP = "https://www.w3.org/ns/activitystreams"
 NS_AP_PUBLIC = f"{NS_AP}#Public"
 # 3 values can be used, see https://www.w3.org/TR/activitypub/#public-addressing
--- a/libervia/backend/plugins/plugin_comp_ap_gateway/http_server.py	Thu Jul 06 11:34:51 2023 +0200
+++ b/libervia/backend/plugins/plugin_comp_ap_gateway/http_server.py	Thu Jul 06 11:34:52 2023 +0200
@@ -41,10 +41,11 @@
 from libervia.backend.memory.sqla_mapping import SubscriptionState
 
 from .constants import (
-    NS_AP, MEDIA_TYPE_AP, CONTENT_TYPE_WEBFINGER, CONTENT_TYPE_AP, TYPE_ACTOR, TYPE_INBOX,
-    TYPE_SHARED_INBOX, TYPE_OUTBOX, TYPE_EVENT, AP_REQUEST_TYPES, PAGE_SIZE,
-    ACTIVITY_TYPES_LOWER, ACTIVIY_NO_ACCOUNT_ALLOWED, SIGN_HEADERS, HS2019, SIGN_EXP,
-    TYPE_FOLLOWERS, TYPE_FOLLOWING, TYPE_ITEM, TYPE_LIKE, TYPE_REACTION, ST_AP_CACHE
+    NS_AP, MEDIA_TYPE_AP, MEDIA_TYPE_AP_ALT, CONTENT_TYPE_WEBFINGER, CONTENT_TYPE_AP,
+    TYPE_ACTOR, TYPE_INBOX, TYPE_SHARED_INBOX, TYPE_OUTBOX, TYPE_EVENT, AP_REQUEST_TYPES,
+    PAGE_SIZE, ACTIVITY_TYPES_LOWER, ACTIVIY_NO_ACCOUNT_ALLOWED, SIGN_HEADERS, HS2019,
+    SIGN_EXP, TYPE_FOLLOWERS, TYPE_FOLLOWING, TYPE_ITEM, TYPE_LIKE, TYPE_REACTION,
+    ST_AP_CACHE
 )
 from .regex import RE_SIG_PARAM
 
@@ -968,7 +969,9 @@
             path
         )
         request_type, extra_args = self.apg.parse_apurl(ap_url)
-        if ((MEDIA_TYPE_AP not in (request.getHeader("accept") or "")
+        header_accept = request.getHeader("accept") or ""
+        if ((MEDIA_TYPE_AP not in header_accept
+             and MEDIA_TYPE_AP_ALT not in header_accept
              and request_type in self.apg.html_redirect)):
             # this is not a AP request, and we have a redirections for it
             kw = {}