diff --git a/barkshark_social/config.py b/barkshark_social/config.py index d4499b2..3c67622 100644 --- a/barkshark_social/config.py +++ b/barkshark_social/config.py @@ -1,6 +1,7 @@ import os import yaml +from blib import Url from copy import deepcopy from pathlib import Path from typing import Any, Generic, TypeVar @@ -96,6 +97,17 @@ class Config(dict[str, dict[str, Any]]): self.path.parent.mkdir(exist_ok = True, parents = True) + @property + def proxy_url(self) -> Url: + return Url( + domain = self.proxy_host, + proto = self.proxy_type, + port = self.proxy_port, + username = self.proxy_user, + password = self.proxy_pass + ) + + @property def sqlite_path(self) -> Path: return self.path.parent.joinpath("database.sqlite3") diff --git a/barkshark_social/server.py b/barkshark_social/server.py index 26dd75b..373ec1d 100644 --- a/barkshark_social/server.py +++ b/barkshark_social/server.py @@ -20,6 +20,7 @@ from .translations import Translations from basgi import ( Application as App, + Client, Request, Response, Template, @@ -40,6 +41,10 @@ class Application(App[Request, RequestState, AppState]): self.state.setup(cfg_path, language) self.error_handlers[HttpError] = self.handle_http_exception + + if self.state.config.proxy_enabled: + self.client = Client(self.name, self.state.config.proxy_url) + self.client.useragent = f"BarksharkSocial/{__version__} (https://{self.config.web_host})" self.add_static(