-
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 #62 from openstreetmap-polska/dev
Release to main
- Loading branch information
Showing
11 changed files
with
102 additions
and
55 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,16 +1,18 @@ | ||
from fastapi import Request | ||
from pyinstrument import Profiler | ||
from starlette.middleware.base import BaseHTTPMiddleware | ||
from starlette.responses import HTMLResponse | ||
|
||
|
||
# https://pyinstrument.readthedocs.io/en/latest/guide.html#profile-a-web-request-in-fastapi | ||
async def profiler_middleware(request: Request, call_next): | ||
profiling = request.query_params.get('profile', False) | ||
if profiling: | ||
profiler = Profiler() | ||
profiler.start() | ||
await call_next(request) | ||
profiler.stop() | ||
return HTMLResponse(profiler.output_html()) | ||
else: | ||
return await call_next(request) | ||
class ProfilerMiddleware(BaseHTTPMiddleware): | ||
# https://pyinstrument.readthedocs.io/en/latest/guide.html#profile-a-web-request-in-fastapi | ||
async def dispatch(self, request: Request, call_next): | ||
profiling = request.query_params.get('profile', False) | ||
if profiling: | ||
profiler = Profiler() | ||
profiler.start() | ||
await call_next(request) | ||
profiler.stop() | ||
return HTMLResponse(profiler.output_html()) | ||
else: | ||
return await call_next(request) |
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,20 @@ | ||
import functools | ||
from collections.abc import Mapping | ||
|
||
from fastapi import Response | ||
|
||
from orjson_response import CustomORJSONResponse | ||
|
||
|
||
def skip_serialization(headers: Mapping[str, str] | None = None): | ||
def decorator(func): | ||
@functools.wraps(func) | ||
async def wrapper(*args, **kwargs): | ||
raw_response = await func(*args, **kwargs) | ||
if isinstance(raw_response, Response): | ||
return raw_response | ||
return CustomORJSONResponse(raw_response, headers=headers) | ||
|
||
return wrapper | ||
|
||
return decorator |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from fastapi import Request | ||
from starlette.middleware.base import BaseHTTPMiddleware | ||
|
||
from config import VERSION | ||
|
||
|
||
async def version_middleware(request: Request, call_next): | ||
response = await call_next(request) | ||
response.headers['X-Version'] = VERSION | ||
return response | ||
class VersionMiddleware(BaseHTTPMiddleware): | ||
async def dispatch(self, request: Request, call_next): | ||
response = await call_next(request) | ||
response.headers['X-Version'] = VERSION | ||
return response |
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