mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
add site url to user agent
This commit is contained in:
parent
2baf2b3a89
commit
be18f16f21
5 changed files with 8 additions and 8 deletions
|
@ -387,7 +387,7 @@ class HttpSignature:
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
headers["User-Agent"] = 'PieFed/1.0'
|
headers["User-Agent"] = f'PieFed/1.0; +https://{current_app.config["SERVER_NAME"]}'
|
||||||
|
|
||||||
# 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)"]
|
||||||
|
|
|
@ -1262,7 +1262,7 @@ def new_instance_profile_task(instance_id: int):
|
||||||
instance.updated_at = utcnow()
|
instance.updated_at = utcnow()
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
headers = {'User-Agent': 'PieFed/1.0', 'Accept': 'application/activity+json'}
|
headers = {'Accept': 'application/activity+json'}
|
||||||
try:
|
try:
|
||||||
nodeinfo = get_request(f"https://{instance.domain}/.well-known/nodeinfo", headers=headers)
|
nodeinfo = get_request(f"https://{instance.domain}/.well-known/nodeinfo", headers=headers)
|
||||||
if nodeinfo.status_code == 200:
|
if nodeinfo.status_code == 200:
|
||||||
|
|
|
@ -232,7 +232,7 @@ def register(app):
|
||||||
try:
|
try:
|
||||||
# Check for dormant or dead instances
|
# Check for dormant or dead instances
|
||||||
instances = Instance.query.filter(Instance.gone_forever == False, Instance.id != 1).all()
|
instances = Instance.query.filter(Instance.gone_forever == False, Instance.id != 1).all()
|
||||||
HEADERS = {'User-Agent': 'PieFed/1.0', 'Accept': 'application/activity+json'}
|
HEADERS = {'Accept': 'application/activity+json'}
|
||||||
|
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
if instance_banned(instance.domain) or instance.domain == 'flipboard.com':
|
if instance_banned(instance.domain) or instance.domain == 'flipboard.com':
|
||||||
|
|
|
@ -85,9 +85,9 @@ def getmtime(filename):
|
||||||
def get_request(uri, params=None, headers=None) -> httpx.Response:
|
def get_request(uri, params=None, headers=None) -> httpx.Response:
|
||||||
timeout = 15 if 'washingtonpost.com' in uri else 5 # Washington Post is really slow on og:image for some reason
|
timeout = 15 if 'washingtonpost.com' in uri else 5 # Washington Post is really slow on og:image for some reason
|
||||||
if headers is None:
|
if headers is None:
|
||||||
headers = {'User-Agent': 'PieFed/1.0'}
|
headers = {'User-Agent': f'PieFed/1.0; +https://{current_app.config["SERVER_NAME"]}'}
|
||||||
else:
|
else:
|
||||||
headers.update({'User-Agent': 'PieFed/1.0'})
|
headers.update({'User-Agent': f'PieFed/1.0; +https://{current_app.config["SERVER_NAME"]}'})
|
||||||
if params and '/webfinger' in uri:
|
if params and '/webfinger' in uri:
|
||||||
payload_str = urllib.parse.urlencode(params, safe=':@')
|
payload_str = urllib.parse.urlencode(params, safe=':@')
|
||||||
else:
|
else:
|
||||||
|
@ -129,9 +129,9 @@ def get_request_instance(uri, instance: Instance, params=None, headers=None) ->
|
||||||
# do a HEAD request to a uri, return the result
|
# do a HEAD request to a uri, return the result
|
||||||
def head_request(uri, params=None, headers=None) -> httpx.Response:
|
def head_request(uri, params=None, headers=None) -> httpx.Response:
|
||||||
if headers is None:
|
if headers is None:
|
||||||
headers = {'User-Agent': 'PieFed/1.0'}
|
headers = {'User-Agent': f'PieFed/1.0; +https://{current_app.config["SERVER_NAME"]}'}
|
||||||
else:
|
else:
|
||||||
headers.update({'User-Agent': 'PieFed/1.0'})
|
headers.update({'User-Agent': f'PieFed/1.0; +https://{current_app.config["SERVER_NAME"]}'})
|
||||||
try:
|
try:
|
||||||
response = httpx_client.head(uri, params=params, headers=headers, timeout=5, allow_redirects=True)
|
response = httpx_client.head(uri, params=params, headers=headers, timeout=5, allow_redirects=True)
|
||||||
except httpx.HTTPError as er:
|
except httpx.HTTPError as er:
|
||||||
|
|
|
@ -13,5 +13,5 @@ worker_class = 'gevent'
|
||||||
accesslog = '-'
|
accesslog = '-'
|
||||||
errorlog = '-'
|
errorlog = '-'
|
||||||
|
|
||||||
max_requests = 5000
|
max_requests = 500
|
||||||
max_requests_jitter = 50
|
max_requests_jitter = 50
|
||||||
|
|
Loading…
Reference in a new issue