Make the application ``Request`` class overridable. (#61)

This commit is contained in:
Michael Lazar 2021-05-11 20:39:49 -04:00 committed by GitHub
parent e6fa299d1e
commit cc4901241f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View File

@ -9,6 +9,10 @@
that include it. that include it.
- Fix incorrect type signature for the EnvironDict type. - Fix incorrect type signature for the EnvironDict type.
#### Changes
- Make the application ``Request`` class overridable.
### v0.8.2 (2021-03-21) ### v0.8.2 (2021-03-21)
#### Fixes #### Fixes

View File

@ -252,6 +252,8 @@ class JetforceApplication:
rate_limiter: typing.Optional[RateLimiter] rate_limiter: typing.Optional[RateLimiter]
routes: typing.List[typing.Tuple[RoutePattern, RouteHandler]] routes: typing.List[typing.Tuple[RoutePattern, RouteHandler]]
request_class: typing.Type[Request] = Request
def __init__(self, rate_limiter: typing.Optional[RateLimiter] = None): def __init__(self, rate_limiter: typing.Optional[RateLimiter] = None):
self.rate_limiter = rate_limiter self.rate_limiter = rate_limiter
self.routes = [] self.routes = []
@ -260,7 +262,7 @@ class JetforceApplication:
self, environ: EnvironDict, send_status: WriteStatusCallable self, environ: EnvironDict, send_status: WriteStatusCallable
) -> ApplicationResponse: ) -> ApplicationResponse:
try: try:
request = Request(environ) request = self.request_class(environ)
except Exception: except Exception:
send_status(Status.BAD_REQUEST, "Invalid URL") send_status(Status.BAD_REQUEST, "Invalid URL")
return return

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import os
import json import json
import os
print("20 application/json") print("20 application/json")
print(json.dumps(dict(os.environ))) print(json.dumps(dict(os.environ)))