From 4635874c125b44f86daca41f2db09eeb95c358ed Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Tue, 20 Dec 2022 13:21:36 +0000 Subject: [PATCH] Relax accept header for gup.pe --- activities/views/debug.py | 5 ++++- core/signatures.py | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/activities/views/debug.py b/activities/views/debug.py index 568a3b4..4272aef 100644 --- a/activities/views/debug.py +++ b/activities/views/debug.py @@ -24,10 +24,13 @@ class JsonViewer(FormView): def form_valid(self, form): raw_result = "" + uri = form.cleaned_data["uri"] + if "://" not in uri: + uri = "https://" + uri try: response = async_to_sync(SystemActor().signed_request)( method="get", - uri=form.cleaned_data["uri"], + uri=uri, ) except httpx.RequestError: result = "Request Error" diff --git a/core/signatures.py b/core/signatures.py index 12e9e97..fba6b5a 100644 --- a/core/signatures.py +++ b/core/signatures.py @@ -183,6 +183,8 @@ class HttpSignature: Performs an async request to the given path, with a document, signed as an identity. """ + if "://" not in uri: + raise ValueError("URI does not contain a scheme") # Create the core header field set uri_parts = urlparse(uri) date_string = http_date() @@ -200,9 +202,7 @@ class HttpSignature: body_bytes = b"" # GET requests get implicit accept headers added if method == "get": - headers[ - "Accept" - ] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' + headers["Accept"] = "application/ld+json" # Sign the headers signed_string = "\n".join( f"{name.lower()}: {value}" for name, value in headers.items()