Commonize onrequest and on response from s3-handler and rest-handler