'Rewrite the ``remote_ip`` and ``protocol`` fields.'

def _apply_xheaders(self, headers):

    ip = headers.get('X-Forwarded-For', self.remote_ip)
    for ip in (cand.strip() for cand in reversed(ip.split(','))):
        if (ip not in self.trusted_downstream):
            break
    ip = headers.get('X-Real-Ip', ip)
    if netutil.is_valid_ip(ip):
        self.remote_ip = ip
    proto_header = headers.get('X-Scheme', headers.get('X-Forwarded-Proto', self.protocol))
    if (proto_header in ('http', 'https')):
        self.protocol = proto_header
