Improved version to use the headers for host/port