add middleware option

the idea came from #8