client middleware