I’m not the original poster, but I’m having the same issue. An apply_filter
would be useful, or even a ternary like below would likely fix for these instances:
$domain_name = $_SERVER['SERVER_NAME'] !== 'localhost' ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST'];
$real_url .= $domain_name . $REQUEST_URI;