From cc4901241fc7d4ec629b3d2fb5590d3473587284 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Tue, 11 May 2021 20:39:49 -0400 Subject: [PATCH] Make the application ``Request`` class overridable. (#61) --- CHANGELOG.md | 4 ++++ jetforce/app/base.py | 4 +++- tests/data/cgi-bin/debug.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) 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)))