-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from feteu/develop
v1.0.5
- Loading branch information
Showing
13 changed files
with
925 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
import uvicorn | ||
from asgi_request_duration import RequestDurationMiddleware | ||
from starlette.applications import Starlette | ||
from starlette.requests import Request | ||
from starlette.responses import JSONResponse | ||
from starlette.routing import Route | ||
|
||
|
||
async def info_endpoint(request: Request) -> JSONResponse: | ||
return JSONResponse({"message": "info"}) | ||
|
||
async def excluded_endpoint(request: Request) -> JSONResponse: | ||
return JSONResponse({"message": "excluded"}) | ||
|
||
routes = [ | ||
Route("/info", info_endpoint, methods=["GET"]), | ||
Route("/excluded", excluded_endpoint, methods=["GET"]), | ||
] | ||
|
||
app = Starlette(routes=routes) | ||
app.add_middleware( | ||
RequestDurationMiddleware, | ||
excluded_paths=["/excluded"], | ||
header_name="x-request-duration", | ||
precision=4, | ||
skip_validate_header_name=False, | ||
skip_validate_precision=False, | ||
) | ||
|
||
if __name__ == "__main__": | ||
log_config = f"{os.path.dirname(__file__)}{os.sep}conf{os.sep}logging.yaml" | ||
config = uvicorn.Config("app:app", host="127.0.0.1", port=8000, log_config=log_config) | ||
server = uvicorn.Server(config) | ||
server.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
version: 1 | ||
filters: | ||
request_duration: | ||
(): 'asgi_request_duration.RequestDurationFilter' | ||
default_value: '-' | ||
formatters: | ||
default: | ||
(): 'uvicorn.logging.DefaultFormatter' | ||
fmt: '%(levelprefix)s [%(asctime)s] %(message)s' | ||
access: | ||
(): 'uvicorn.logging.AccessFormatter' | ||
fmt: '%(levelprefix)s [%(asctime)s] %(client_addr)s - "%(request_line)s" %(status_code)s {%(request_duration)s}' | ||
handlers: | ||
default: | ||
class: logging.StreamHandler | ||
formatter: default | ||
stream: ext://sys.stderr | ||
access: | ||
class: logging.StreamHandler | ||
filters: [request_duration] | ||
formatter: access | ||
stream: ext://sys.stdout | ||
loggers: | ||
uvicorn: | ||
level: INFO | ||
handlers: | ||
- default | ||
uvicorn.error: | ||
level: INFO | ||
uvicorn.access: | ||
level: INFO | ||
propagate: False | ||
handlers: | ||
- access |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from asgi_request_duration import RequestDurationMiddleware | ||
from starlette.applications import Starlette | ||
from starlette.requests import Request | ||
from starlette.responses import JSONResponse | ||
from starlette.routing import Route | ||
from uvicorn import run | ||
|
||
|
||
async def info_endpoint(request: Request) -> JSONResponse: | ||
return JSONResponse({"message": "info"}) | ||
|
||
async def excluded_endpoint(request: Request) -> JSONResponse: | ||
return JSONResponse({"message": "excluded"}) | ||
|
||
routes = [ | ||
Route("/info", info_endpoint, methods=["GET"]), | ||
Route("/excluded", excluded_endpoint, methods=["GET"]), | ||
] | ||
|
||
app = Starlette(routes=routes) | ||
app.add_middleware( | ||
RequestDurationMiddleware, | ||
excluded_paths=["/excluded"], | ||
header_name="x-request-duration", | ||
precision=4, | ||
skip_validate_header_name=False, | ||
skip_validate_precision=False, | ||
) | ||
|
||
if __name__ == "__main__": | ||
run(app, host='127.0.0.1', port=8000) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.