Use valid HTTP headers to get req.baseUrl and port

Closes #1702.