Skip to content

Commit

Permalink
middleware now skips non-http/ws requests
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-oleshkevich committed Nov 15, 2022
1 parent 41ee54c commit 8ea0cb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions starlette_babel/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ def __init__(
]

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
if scope['type'] not in ('http', 'websocket'):
await self.app(scope, receive, send)
return

async def send_wrapper(message: Message) -> None:
if message["type"] == "http.response.start":
message["headers"].append(tuple([b"content-language", scope["state"]["language"].encode()]))
Expand Down
4 changes: 4 additions & 0 deletions starlette_babel/timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def __init__(
]

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
if scope['type'] not in ('http', 'websocket'):
await self.app(scope, receive, send)
return

conn = HTTPConnection(scope)
tz = self.detect_timezone(conn) or self.fallback
try:
Expand Down

0 comments on commit 8ea0cb6

Please sign in to comment.