misc: make middlewares compatible with MIDDLEWARE settings (#36335)

This commit is contained in:
Frédéric Péters 2019-09-22 20:04:17 +02:00
parent 0f7bffd1b2
commit 177cc97059
7 changed files with 13 additions and 11 deletions

View File

@ -2,8 +2,9 @@ import os.path
from django.conf import settings
from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin
class CORSMiddleware(object):
class CORSMiddleware(MiddlewareMixin):
def process_request(self, request):
"""
If CORS preflight header, then create an

View File

@ -20,14 +20,10 @@ import time
import django
from django.db import connection
from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin
import prometheus_client
if django.VERSION >= (1, 10, 0):
from django.utils.deprecation import MiddlewareMixin
else:
MiddlewareMixin = object
requests_total_by_host_view_status_method = prometheus_client.Counter(
'django_http_requests_total_by_host_view_status_method',

View File

@ -1,6 +1,7 @@
import threading
from django.utils.deprecation import MiddlewareMixin
class StoreRequestMiddleware(object):
class StoreRequestMiddleware(MiddlewareMixin):
collection = {}
def process_request(self, request):

View File

@ -1,10 +1,11 @@
import json
from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin
from hobo.scrutiny.wsgi import middleware
class VersionMiddleware(object):
class VersionMiddleware(MiddlewareMixin):
def process_request(self, request):
if request.method == 'GET' and (request.path == '/__version__' or
request.path == '/__version__/'):

View File

@ -1,7 +1,8 @@
from django.conf import settings
from django.utils.deprecation import MiddlewareMixin
class XForwardedForMiddleware(object):
class XForwardedForMiddleware(MiddlewareMixin):
'''Copy the first address from X-Forwarded-For header to the REMOTE_ADDR meta.
This middleware should only be used if you are sure the header cannot be

View File

@ -2,6 +2,7 @@ import os
import glob
import hashlib
from django.utils.deprecation import MiddlewareMixin
from django.utils.encoding import smart_bytes
from django.conf import settings
from django.db import connection
@ -14,7 +15,7 @@ SENTINEL = object()
class TenantNotFound(RuntimeError):
pass
class TenantMiddleware(object):
class TenantMiddleware(MiddlewareMixin):
"""
This middleware should be placed at the very top of the middleware stack.
Selects the proper database schema using the request host. Can fail in

View File

@ -1,4 +1,5 @@
from django.utils.six.moves.urllib.parse import quote
from django.utils.deprecation import MiddlewareMixin
import json
import pkg_resources
@ -7,7 +8,7 @@ try:
except ImportError:
apt_cache = None
class VersionMiddleware(object):
class VersionMiddleware(MiddlewareMixin):
ENTROUVERT_PACKAGES = [
'wcs',
'wcs-au-quotidien',