Make the application ``Request`` class overridable. (#61)
This commit is contained in:
parent
e6fa299d1e
commit
cc4901241f
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)))
|
||||||
|
|
Loading…
Reference in New Issue