-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae2992a
commit 41adbaa
Showing
2 changed files
with
46 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from asgiref.sync import iscoroutinefunction | ||
from django.utils.decorators import async_only_middleware, sync_only_middleware | ||
|
||
|
||
@sync_only_middleware | ||
def sync_middleware_1(get_response): | ||
def middleware(request): | ||
response = get_response(request) | ||
return response | ||
|
||
return middleware | ||
|
||
|
||
@async_only_middleware | ||
def async_middleware_1(get_response): | ||
async def middleware(request): | ||
response = await get_response(request) | ||
return response | ||
|
||
return middleware | ||
|
||
|
||
@sync_only_middleware | ||
def sync_middleware_2(get_response): | ||
def middleware(request): | ||
response = get_response(request) | ||
return response | ||
|
||
return middleware | ||
|
||
|
||
@async_only_middleware | ||
def async_middleware_2(get_response): | ||
async def middleware(request): | ||
response = await get_response(request) | ||
return response | ||
|
||
return middleware |