I'm trying to delete Server header from django rest framework response, but I didn't find an easy way, so I create a middleware to delete it.
This is my first try:
middleware.py
class RemoveHeaders(object):
def process_response(self, request, response):
response['Server'] = ''
return response
This middleware works ok, but the problem is that it fills server header with empty string and not delete it. so I tried the next:
class RemoveHeaders(object):
def process_response(self, request, response):
del response['Server']
return response
But It doesn't work. server header continues.
How can I delete server header?, or do you know another alternative?
thanks
Updated, these are my middlewares, maybe someone is override server header, case it doesn't exist?
MIDDLEWARE_CLASSES = (
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'my_api.middleware.RemoveHeaders'
)
Server: WSGIServer/0.2 CPython/3.5.3proxy_set_header