Verified Commit b5ff339e authored by Eliot Berriot's avatar Eliot Berriot
Browse files

We now use a proper user agent including instance version and url during outgoing requests

parent 99200ad0
......@@ -149,16 +149,6 @@ FIXTURE_DIRS = (
# ------------------------------------------------------------------------------
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
# MANAGER CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
ADMINS = (
("""Eliot Berriot""", 'contact@eliotberriot.om'),
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
MANAGERS = ADMINS
# DATABASE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
......
import requests
from django.conf import settings
import funkwhale_api
def get_user_agent():
return 'python-requests (funkwhale/{}; +{})'.format(
funkwhale_api.__version__,
settings.FUNKWHALE_URL
)
def get_session():
s = requests.Session()
s.headers['User-Agent'] = get_user_agent()
return s
import os
import requests
import json
from urllib.parse import quote_plus
import youtube_dl
......
import logging
import json
import requests
import requests_http_signature
import uuid
from funkwhale_api.common import session
from . import models
from . import signing
......@@ -68,7 +69,7 @@ def deliver(activity, on_behalf_of, to=[]):
recipient_actor = actors.get_actor(url)
logger.debug('delivering to %s', recipient_actor.inbox_url)
logger.debug('activity content: %s', json.dumps(activity))
response = requests.post(
response = session.get_session().post(
auth=auth,
json=activity,
url=recipient_actor.inbox_url,
......
import logging
import requests
import uuid
import xml
......@@ -12,6 +11,8 @@ from rest_framework.exceptions import PermissionDenied
from dynamic_preferences.registries import global_preferences_registry
from funkwhale_api.common import session
from . import activity
from . import keys
from . import models
......@@ -28,7 +29,7 @@ def remove_tags(text):
def get_actor_data(actor_url):
response = requests.get(
response = session.get_session().get(
actor_url,
headers={
'Accept': 'application/activity+json',
......
......@@ -3,7 +3,6 @@ from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.backends import default_backend as crypto_default_backend
import re
import requests
import urllib.parse
from . import exceptions
......
import ffmpeg
import os
import json
import requests
import subprocess
import unicodedata
import urllib
......@@ -23,6 +22,7 @@ from rest_framework import permissions
from musicbrainzngs import ResponseError
from funkwhale_api.common import utils as funkwhale_utils
from funkwhale_api.common import session
from funkwhale_api.federation import actors
from funkwhale_api.requests.models import ImportRequest
from funkwhale_api.musicbrainz import api
......@@ -214,7 +214,7 @@ class TrackFileViewSet(viewsets.ReadOnlyModelViewSet):
file_extension = utils.get_ext_from_type(mt)
filename = '{}.{}'.format(f.track.full_name, file_extension)
auth = actors.SYSTEM_ACTORS['library'].get_request_auth()
remote_response = requests.get(
remote_response = session.get_session().get(
library_track.audio_url,
auth=auth,
stream=True,
......
......@@ -5,7 +5,7 @@ from django.conf import settings
from funkwhale_api import __version__
_api = musicbrainzngs
_api.set_useragent('funkwhale', str(__version__), 'contact@eliotberriot.com')
_api.set_useragent('funkwhale', str(__version__), settings.FUNKWHALE_URL)
store = memoize.djangocache.Cache('default')
......
import funkwhale_api
from funkwhale_api.common import session
def test_get_user_agent(settings):
settings.FUNKWHALE_URL = 'https://test.com'
'http.rb/3.0.0 (Mastodon/2.2.0; +https://mastodon.eliotberriot.com/)'
expected = 'python-requests (funkwhale/{}; +{})'.format(
funkwhale_api.__version__,
settings.FUNKWHALE_URL
)
assert session.get_user_agent() == expected
def test_get_session():
expected = session.get_user_agent()
assert session.get_session().headers['User-Agent'] == expected
We now use a proper user agent including instance version and url during
outgoing requests
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment