Custom middleware for XHR requests