middleware to alter request and response