diff --git a/pyproject.toml b/pyproject.toml index 5f2dc91..7878d3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "spiderweb-framework" -version = "0.11.0" +version = "0.12.0" description = "A small web framework, just big enough for a spider." authors = ["Joe Kaufeld "] readme = "README.md" diff --git a/spiderweb/constants.py b/spiderweb/constants.py index cf8734d..9ebc2ad 100644 --- a/spiderweb/constants.py +++ b/spiderweb/constants.py @@ -2,7 +2,7 @@ from peewee import DatabaseProxy DEFAULT_ALLOWED_METHODS = ["GET"] DEFAULT_ENCODING = "UTF-8" -__version__ = "0.11.0" +__version__ = "0.12.0" # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie REGEX_COOKIE_NAME = r"^[a-zA-Z0-9\s\(\)<>@,;:\/\\\[\]\?=\{\}\"\t]*$" diff --git a/spiderweb/main.py b/spiderweb/main.py index b0333dc..17ac9ca 100644 --- a/spiderweb/main.py +++ b/spiderweb/main.py @@ -49,6 +49,7 @@ class SpiderwebRouter(LocalServerMixin, MiddlewareMixin, RoutesMixin, FernetMixi staticfiles_dirs: list[str] = None, routes: list[tuple[str, Callable] | tuple[str, Callable, dict]] = None, error_routes: dict[int, Callable] = None, + allowed_hosts=None, secret_key: str = None, session_max_age=60 * 60 * 24 * 14, # 2 weeks session_cookie_name="swsession", @@ -69,9 +70,10 @@ class SpiderwebRouter(LocalServerMixin, MiddlewareMixin, RoutesMixin, FernetMixi self.append_slash = append_slash self.templates_dirs = templates_dirs self.staticfiles_dirs = staticfiles_dirs - self._middleware: list[str] = middleware if middleware else [] + self._middleware: list[str] = middleware or [] self.middleware: list[Callable] = [] self.secret_key = secret_key if secret_key else self.generate_key() + self.allowed_hosts = allowed_hosts or ["*"] self.extra_data = kwargs diff --git a/spiderweb/middleware/cors.py b/spiderweb/middleware/cors.py new file mode 100644 index 0000000..37de52b --- /dev/null +++ b/spiderweb/middleware/cors.py @@ -0,0 +1 @@ +# https://gist.github.com/FND/204ba41bf6ae485965ef diff --git a/spiderweb/request.py b/spiderweb/request.py index 6f95cde..a617e99 100644 --- a/spiderweb/request.py +++ b/spiderweb/request.py @@ -72,6 +72,9 @@ class Request: ] for f in fields: self.META[f] = self.environ.get(f) + for f in self.environ.keys(): + if f.startswith("HTTP_"): + self.META[f] = self.environ[f] self.META["client_address"] = get_client_address(self.environ) def populate_cookies(self) -> None: diff --git a/templates/test.html b/templates/test.html index db08db0..6fa59b6 100644 --- a/templates/test.html +++ b/templates/test.html @@ -15,4 +15,7 @@

AAAAAAAAAA

+

+ {{ request.META }} +

{% endblock %}