Compare commits

..

No commits in common. "f7e31d9387c163480b9c32bd7c183d87cc67104e" and "beb9d9c3e5bbb805f00f856526b57752a342d22f" have entirely different histories.

7 changed files with 12 additions and 32 deletions

View file

@ -315,11 +315,11 @@ class PushWorker(multiprocessing.Process):
while not self.shutdown.is_set():
try:
inbox, message, instance = self.queue.get(block=True, timeout=0.1)
asyncio.create_task(client.post(inbox, message, instance))
inbox, message, instance = self.queue.get(block=True, timeout=0.25)
await client.post(inbox, message, instance)
except Empty:
await asyncio.sleep(0)
pass
# make sure an exception doesn't bring down the worker
except Exception:

View file

@ -14,7 +14,7 @@
%link(rel="stylesheet" type="text/css" href="/theme/{{config.theme}}.css" nonce="{{view.request['hash']}}" class="theme")
%link(rel="stylesheet" type="text/css" href="/static/style.css" nonce="{{view.request['hash']}}")
%link(rel="manifest" href="/manifest.json")
%script(type="application/javascript" src="/static/api.js" nonce="{{view.request['hash']}}" defer)
%script(type="application/javascript" src="/static/api.js" nonce="{{view.request['hash']}}", defer)
-block head
%body

View file

@ -137,13 +137,11 @@ class HttpClient:
logging.verbose('Failed to parse JSON')
return None
except ClientSSLError as e:
except ClientSSLError:
logging.verbose('SSL error when connecting to %s', urlparse(url).netloc)
logging.warning(str(e))
except (AsyncTimeoutError, ClientConnectionError) as e:
except (AsyncTimeoutError, ClientConnectionError):
logging.verbose('Failed to connect to %s', urlparse(url).netloc)
logging.warning(str(e))
except Exception:
traceback.print_exc()
@ -212,13 +210,11 @@ class HttpClient:
logging.debug("headers: %s", json.dumps(headers, indent = 4))
return
except ClientSSLError as e:
except ClientSSLError:
logging.warning('SSL error when pushing to %s', urlparse(url).netloc)
logging.warning(str(e))
except (AsyncTimeoutError, ClientConnectionError) as e:
except (AsyncTimeoutError, ClientConnectionError):
logging.warning('Failed to connect to %s for message push', urlparse(url).netloc)
logging.warning(str(e))
# prevent workers from being brought down
except Exception:

View file

@ -116,7 +116,7 @@ class ActorView(View):
return Response.new_error(400, 'actor missing public key', 'json')
try:
await self.signer.validate_request_async(self.request)
await self.signer.validate_aiohttp_request(self.request)
except aputils.SignatureFailureError as e:
logging.verbose('signature validation failed for "%s": %s', self.actor.id, e)

View file

@ -18,12 +18,6 @@ if typing.TYPE_CHECKING:
from typing import Any
ALLOWED_HEADERS = {
'accept',
'authorization',
'content-type'
}
PUBLIC_API_PATHS: Sequence[tuple[str, str]] = (
('GET', '/api/v1/relay'),
('GET', '/api/v1/instance'),
@ -54,20 +48,14 @@ async def handle_api_path(request: Request, handler: Callable) -> Response:
request['token'] = None
request['user'] = None
if request.method != "OPTIONS" and check_api_path(request.method, request.path):
if check_api_path(request.method, request.path):
if not request['token']:
return Response.new_error(401, 'Missing token', 'json')
if not request['user']:
return Response.new_error(401, 'Invalid token', 'json')
response = await handler(request)
if request.path.startswith('/api'):
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Headers'] = ', '.join(ALLOWED_HEADERS)
return response
return await handler(request)
@register_route('/api/v1/token')

View file

@ -62,10 +62,6 @@ class View(AbstractView):
return await handler(self.request, **self.request.match_info, **kwargs)
async def options(self, request: Request) -> Response:
return Response.new()
@cached_property
def allowed_methods(self) -> Sequence[str]:
return tuple(self.handlers.keys())

View file

@ -44,7 +44,7 @@ async def handle_frontend_path(request: web.Request, handler: Callable) -> Respo
response = await handler(request)
if not request.path.startswith('/api') and not request['user'] and request['token']:
if not request['user'] and request['token']:
response.del_cookie('user-token')
return response