Added proper headers to middleware, tests to prove it.