I'd rather encapasulate this behavior in Endpoint class so can you change this to endpoint.rewriteUrl(url) and add a new method to the Endpoint class to handle this