Middlewares

synopsis:

Middlewares in django-boost

RedirectCorrectHostnameMiddleware

class django_boost.middleware.RedirectCorrectHostnameMiddleware(get_response)

Redirect to correct hostname.

if requested hostname and settings.CORRECT_HOST does not match.

You will need to add the RedirectCorrectHostnameMiddleware to the MIDDLEWARE setting of your Django project settings.py file.

MIDDLEWARE = [
    'django_boost.middleware.RedirectCorrectHostnameMiddleware',  # add
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    ...
]

CORRECT_HOST = ‘sample.com’

Redirect all access to the domain specified in CORRECT_HOST

It is not redirected when DEBUG = True

This is useful when migrating domains

Originally it should be done with server software such as nginx and apache,

but it is useful when the setting is troublesome or when using services such as heroku.

HttpStatusCodeExceptionMiddleware

class django_boost.middleware.HttpStatusCodeExceptionMiddleware(get_response)

Handle status code exceptions.

similar to the Http404 exception.

You will need to add the HttpStatusCodeExceptionMiddleware to the MIDDLEWARE setting of your Django project settings.py file.

MIDDLEWARE = [
    'django_boost.middleware.HttpStatusCodeExceptionMiddleware',  # add
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    ...
]

This Middleware is required when using the HttpStatusCode Exceptions.

SpaceLessMiddleware

class django_boost.middleware.SpaceLessMiddleware(get_response)

Middleware that remove white space in HTML.

You will need to add the SpaceLessMiddleware to the MIDDLEWARE setting of your Django project settings.py file.

MIDDLEWARE = [
    'django_boost.middleware.SpaceLessMiddleware',  # add
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    ...
]

Install so that it is executed before middleware to compress such as GZipMiddleware.