def channel_cors(sender, request, **kwargs):
"""
This signal checks for channel `CORS_ORIGIN_WHITELIST` settings.
If the channel as a setting where the value match the Origin header
the request will have the correct Access-Control-Allow-Origin on the response.
"""
channel = get_channel(request.channel)
if channel:
origin = request.META.get("HTTP_ORIGIN", "")
domain = urlparse(origin).netloc
if domain in channel["settings"].get("CORS_ORIGIN_WHITELIST", []):
return True
return False
# check_request_enabled.connect(channel_cors)
# Custom channel signal
signals.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录