Headers
Headers
Introduction
Masonite allows you to easily add security headers to your application. Masonite adds some sensible defaults but you can modify them as you need.
Configuration
All you need to do is add the middleware to your HTTP_MIDDLEWARE
constant in your config/middleware.py
file:
This will add these default headers for your server:
Overriding Headers
If you want to change or add any headers, you just need to specify them in your config/middleware.py file and this middleware will automatically pick them up. For example you can change the X-Frame-Options
header like this:
This will then change your headers to:
Notice the change in the new header we changed.
CORS
You may also choose to use CORS for your application for advanced security measures. Using CORS is very similar to the secure headers above.
To get started just import the CorsMiddleware
class into your config/middleware.py
file and add it to your HTTP_MIDDLEWARE
list:
Then below this list you can put your CORS headers as a dictionary. Here is a list of sensible defaults:
Now if you go to a browser you will see these headers being sent as a response from your server.
Last updated