fix: headers

pull/8/head
db0 2023-06-24 13:43:19 +02:00
parent b1122ac048
commit 323809afea
4 changed files with 15 additions and 8 deletions

View File

@ -7,7 +7,7 @@ from fediseer.flask import OVERSEER
from fediseer.routes import * from fediseer.routes import *
from fediseer.apis import apiv1 from fediseer.apis import apiv1
from fediseer.argparser import args from fediseer.argparser import args
from fediseer.consts import OVERSEER_VERSION from fediseer.consts import FEDISEER_VERSION
OVERSEER.register_blueprint(apiv1) OVERSEER.register_blueprint(apiv1)
@ -18,5 +18,5 @@ def after_request(response):
response.headers["Access-Control-Allow-Origin"] = "*" response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS, PUT, DELETE, PATCH" response.headers["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS, PUT, DELETE, PATCH"
response.headers["Access-Control-Allow-Headers"] = "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, apikey, Client-Agent, X-Fields" response.headers["Access-Control-Allow-Headers"] = "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, apikey, Client-Agent, X-Fields"
response.headers["Fediseer-Node"] = f"{socket.gethostname()}:{args.port}:{OVERSEER_VERSION}" response.headers["Fediseer-Node"] = f"{socket.gethostname()}:{args.port}:{FEDISEER_VERSION}"
return response return response

View File

@ -1,4 +1,4 @@
OVERSEER_VERSION = "0.5.0" FEDISEER_VERSION = "0.5.0"
SUPPORTED_SOFTWARE = [ SUPPORTED_SOFTWARE = [
"lemmy", "lemmy",
"mastodon", "mastodon",

View File

@ -1,6 +1,7 @@
import requests import requests
from loguru import logger from loguru import logger
from pythorhead import Lemmy from pythorhead import Lemmy
from fediseer.consts import FEDISEER_VERSION
def get_lemmy_admins(domain): def get_lemmy_admins(domain):
requested_lemmy = Lemmy(f"https://{domain}") requested_lemmy = Lemmy(f"https://{domain}")
@ -36,11 +37,11 @@ def get_nodeinfo(domain):
"Sec-Fetch-Site": "none", "Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1", "Sec-Fetch-User": "?1",
"Sec-GPC": "1", "Sec-GPC": "1",
"User-Agent": "Fediseer/0.5", "User-Agent": f"Fediseer/{FEDISEER_VERSION}",
} }
wellknown = requests.get(f"https://{domain}/.well-known/nodeinfo", headers=headers, timeout=4).json() wellknown = requests.get(f"https://{domain}/.well-known/nodeinfo", headers=headers, timeout=3).json()
headers["Sec-Fetch-Site"] = "cross-site" headers["Sec-Fetch-Site"] = "cross-site"
nodeinfo = requests.get(wellknown['links'][0]['href'], headers=headers, timeout=2).json() nodeinfo = requests.get(wellknown['links'][0]['href'], headers=headers, timeout=3).json()
return nodeinfo return nodeinfo
except Exception as err: except Exception as err:
logger.debug(err) logger.debug(err)

View File

@ -12,7 +12,7 @@ import fediseer.exceptions as e
from pythorhead import Lemmy from pythorhead import Lemmy
from loguru import logger from loguru import logger
from fediseer.database import functions as database from fediseer.database import functions as database
from fediseer.consts import SUPPORTED_SOFTWARE from fediseer.consts import SUPPORTED_SOFTWARE, FEDISEER_VERSION
from fediseer.fediverse import get_admin_for_software from fediseer.fediverse import get_admin_for_software
class ActivityPubPM: class ActivityPubPM:
@ -92,7 +92,13 @@ class ActivityPubPM:
'Date': date, 'Date': date,
'Signature': header, 'Signature': header,
'Digest': digest_header, 'Digest': digest_header,
'Content-Type': 'application/ld+json; profile="http://www.w3.org/ns/activitystreams"' 'Content-Type': 'application/ld+json; profile="http://www.w3.org/ns/activitystreams"',
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Sec-GPC": "1",
"User-Agent": f"Fediseer/{FEDISEER_VERSION}",
} }
url = f"https://{domain}/inbox" url = f"https://{domain}/inbox"
response = requests.post(url, data=document, headers=headers) response = requests.post(url, data=document, headers=headers)