2023-05-03 21:42:37 -07:00
|
|
|
from users.models import Domain
|
2022-11-16 20:42:25 -08:00
|
|
|
|
2022-11-06 12:48:04 -08:00
|
|
|
|
2023-05-03 21:42:37 -07:00
|
|
|
class DomainMiddleware:
|
2022-11-06 12:48:04 -08:00
|
|
|
"""
|
2023-05-03 21:42:37 -07:00
|
|
|
Tries to attach a Domain object to every incoming request, if one matches.
|
2022-11-06 12:48:04 -08:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, get_response):
|
|
|
|
self.get_response = get_response
|
|
|
|
|
|
|
|
def __call__(self, request):
|
2023-05-03 21:42:37 -07:00
|
|
|
request.domain = None
|
|
|
|
if "host" in request.headers:
|
|
|
|
request.domain = Domain.get_domain(request.headers["host"])
|
2022-11-06 12:48:04 -08:00
|
|
|
response = self.get_response(request)
|
|
|
|
return response
|