Enforce Hostname Middleware
|Reported by:||robballou||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
For a recent project, I wanted to be able to enforce the hostname used in requests to a single domain (in this case, any requests like "www.example.com" would redirect to "example.com"). Rather than use the redirect app, I felt this was better suited to middleware like the
PREPEND_WWW setting. So the following middleware will allow users to set an
ENFORCE_HOSTNAME setting for a single or multiple hosts (string or list).
I wasn't sure how to submit a patch for the middleware itself, so that is just attached as a file. I did create tests for the middleware though.