diff --git a/CHANGELOG.md b/CHANGELOG.md index e395f6d..f9bf2ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ that include it. - Fix incorrect type signature for the EnvironDict type. +#### Changes + +- Make the application ``Request`` class overridable. + ### v0.8.2 (2021-03-21) #### Fixes diff --git a/jetforce/app/base.py b/jetforce/app/base.py index b42e598..ac42cf0 100644 --- a/jetforce/app/base.py +++ b/jetforce/app/base.py @@ -252,6 +252,8 @@ class JetforceApplication: rate_limiter: typing.Optional[RateLimiter] routes: typing.List[typing.Tuple[RoutePattern, RouteHandler]] + request_class: typing.Type[Request] = Request + def __init__(self, rate_limiter: typing.Optional[RateLimiter] = None): self.rate_limiter = rate_limiter self.routes = [] @@ -260,7 +262,7 @@ class JetforceApplication: self, environ: EnvironDict, send_status: WriteStatusCallable ) -> ApplicationResponse: try: - request = Request(environ) + request = self.request_class(environ) except Exception: send_status(Status.BAD_REQUEST, "Invalid URL") return diff --git a/tests/data/cgi-bin/debug.py b/tests/data/cgi-bin/debug.py index 9eb8b4b..71db77e 100755 --- a/tests/data/cgi-bin/debug.py +++ b/tests/data/cgi-bin/debug.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import os import json +import os print("20 application/json") print(json.dumps(dict(os.environ)))