|
2 | 2 | from django.contrib.auth import authenticate |
3 | 3 | from django.utils.cache import patch_vary_headers |
4 | 4 |
|
5 | | -from .models import Application |
| 5 | +from .models import AbstractApplication, Application |
6 | 6 |
|
7 | 7 |
|
8 | 8 | class OAuth2TokenMiddleware: |
@@ -45,18 +45,22 @@ def __call__(self, request): |
45 | 45 | METHODS = ("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS") |
46 | 46 |
|
47 | 47 |
|
48 | | -class CorsMiddleware(object): |
49 | | - def process_request(self, request): |
| 48 | +class CorsMiddleware: |
| 49 | + |
| 50 | + def __init__(self, get_response): |
| 51 | + self.get_response = get_response |
| 52 | + |
| 53 | + def __call__(self, request): |
50 | 54 | """If this is a preflight-request, we must always return 200""" |
51 | 55 | if request.method == "OPTIONS" and "HTTP_ACCESS_CONTROL_REQUEST_METHOD" in request.META: |
52 | | - return http.HttpResponse() |
53 | | - return None |
| 56 | + response = http.HttpResponse() |
| 57 | + else: |
| 58 | + response = self.get_response(request) |
54 | 59 |
|
55 | | - def process_response(self, request, response): |
56 | 60 | """Add cors-headers to request if they can be derived correctly""" |
57 | 61 | try: |
58 | 62 | cors_allow_origin = _get_cors_allow_origin_header(request) |
59 | | - except Application.NoSuitableOriginFoundError: |
| 63 | + except AbstractApplication.NoSuitableOriginFoundError: |
60 | 64 | pass |
61 | 65 | else: |
62 | 66 | response["Access-Control-Allow-Origin"] = cors_allow_origin |
|
0 commit comments