Test for middleware and locals

Adding tests for middleware and locals. Also covers use of a custom ``CID_HEADER`` setting