ticket:3 - fix midelware, add tests
ticket:3 - fix
Merge branch 't3_middleware'