comparison sat/plugins/plugin_comp_ap_gateway/http_server.py @ 3994:69d970f974ff

component AP gateway: don't percent-encode `@`: Mastodon doesn't like when "@" is percent-encoded (because it doesn't do it, and it checks that the URL matches the ID without taking care of percent-encoding).
author Goffi <goffi@goffi.org>
date Fri, 10 Feb 2023 17:20:02 +0100
parents 1c84268752a1
children 27e5294649c2
comparison
equal deleted inserted replaced
3993:722c25818778 3994:69d970f974ff
590 "@context": [ 590 "@context": [
591 "https://www.w3.org/ns/activitystreams", 591 "https://www.w3.org/ns/activitystreams",
592 "https://w3id.org/security/v1" 592 "https://w3id.org/security/v1"
593 ], 593 ],
594 594
595 "id": ap_url, 595 # XXX: Mastodon doesn't like percent-encode arobas, so we have to unescape it
596 # if it is escaped
597 "id": ap_url.replace("%40", "@"),
596 "type": "Person", 598 "type": "Person",
597 "preferredUsername": preferred_username, 599 "preferredUsername": preferred_username,
598 "inbox": inbox, 600 "inbox": inbox,
599 "outbox": outbox, 601 "outbox": outbox,
600 "events": events, 602 "events": events,
635 637
636 def getCanonicalURL(self, request: "HTTPRequest") -> str: 638 def getCanonicalURL(self, request: "HTTPRequest") -> str:
637 return parse.urljoin( 639 return parse.urljoin(
638 f"https://{self.apg.public_url}", 640 f"https://{self.apg.public_url}",
639 request.path.decode().rstrip("/") 641 request.path.decode().rstrip("/")
640 ) 642 # we unescape "@" for the same reason as in [APActorRequest]
643 ).replace("%40", "@")
641 644
642 def queryData2RSMRequest( 645 def queryData2RSMRequest(
643 self, 646 self,
644 query_data: Dict[str, List[str]] 647 query_data: Dict[str, List[str]]
645 ) -> rsm.RSMRequest: 648 ) -> rsm.RSMRequest: