mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-25 08:41:00 +00:00
Set a Takahe User-Agent header for signed requests (#142)
This commit is contained in:
parent
126c7a14ec
commit
39a40e4dae
3 changed files with 15 additions and 1 deletions
|
@ -5,6 +5,7 @@ from typing import Optional
|
||||||
import httpx
|
import httpx
|
||||||
import urlman
|
import urlman
|
||||||
from asgiref.sync import async_to_sync, sync_to_async
|
from asgiref.sync import async_to_sync, sync_to_async
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.postgres.indexes import GinIndex
|
from django.contrib.postgres.indexes import GinIndex
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.template.defaultfilters import linebreaks_filter
|
from django.template.defaultfilters import linebreaks_filter
|
||||||
|
@ -696,7 +697,10 @@ class Post(StatorModel):
|
||||||
"""
|
"""
|
||||||
response = httpx.get(
|
response = httpx.get(
|
||||||
self.object_uri,
|
self.object_uri,
|
||||||
headers={"Accept": "application/json"},
|
headers={
|
||||||
|
"Accept": "application/json",
|
||||||
|
"User-Agent": settings.TAKAHE_USER_AGENT,
|
||||||
|
},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
if 200 <= response.status_code < 300:
|
if 200 <= response.status_code < 300:
|
||||||
|
|
|
@ -220,6 +220,10 @@ class HttpSignature:
|
||||||
"algorithm": "rsa-sha256",
|
"algorithm": "rsa-sha256",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Announce ourselves with an agent similar to Mastodon
|
||||||
|
headers["User-Agent"] = settings.TAKAHE_USER_AGENT
|
||||||
|
|
||||||
# Send the request with all those headers except the pseudo one
|
# Send the request with all those headers except the pseudo one
|
||||||
del headers["(request-target)"]
|
del headers["(request-target)"]
|
||||||
async with httpx.AsyncClient(timeout=timeout) as client:
|
async with httpx.AsyncClient(timeout=timeout) as client:
|
||||||
|
|
|
@ -7,6 +7,7 @@ from typing import Literal
|
||||||
|
|
||||||
import dj_database_url
|
import dj_database_url
|
||||||
import django_cache_url
|
import django_cache_url
|
||||||
|
import httpx
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
from pydantic import AnyUrl, BaseSettings, EmailStr, Field, validator
|
from pydantic import AnyUrl, BaseSettings, EmailStr, Field, validator
|
||||||
from sentry_sdk.integrations.django import DjangoIntegration
|
from sentry_sdk.integrations.django import DjangoIntegration
|
||||||
|
@ -354,3 +355,8 @@ CACHES = {"default": django_cache_url.parse(SETUP.CACHES_DEFAULT or "dummy://")}
|
||||||
|
|
||||||
if SETUP.ERROR_EMAILS:
|
if SETUP.ERROR_EMAILS:
|
||||||
ADMINS = [("Admin", e) for e in SETUP.ERROR_EMAILS]
|
ADMINS = [("Admin", e) for e in SETUP.ERROR_EMAILS]
|
||||||
|
|
||||||
|
TAKAHE_USER_AGENT = (
|
||||||
|
f"python-httpx/{httpx.__version__} "
|
||||||
|
f"(Takahe/{__version__}; +https://{SETUP.MAIN_DOMAIN}/)"
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue