'Perform setup tasks before the controller method/action is executed.
Called by WSGIController.__call__.'

def __before__(self):

    forwarded_proto = request.environ.get('HTTP_X_FORWARDED_PROTO', 'http')
    forwarded_proto = forwarded_proto.lower()
    assert (forwarded_proto in ('http', 'https'))
    request.environ['wsgi.url_scheme'] = forwarded_proto
    forwarded_for = request.environ.get('HTTP_X_FORWARDED_FOR', ())
    remote_addr = request.environ.get('REMOTE_ADDR')
    request.via_cdn = False
    cdn_ip = g.cdn_provider.get_client_ip(request.environ)
    if cdn_ip:
        request.ip = cdn_ip
        request.via_cdn = True
    elif (g.trust_local_proxies and forwarded_for and is_local_address(remote_addr)):
        request.ip = forwarded_for.split(',')[(-1)]
    else:
        request.ip = request.environ['REMOTE_ADDR']
    try:
        request.params
        request.path
    except UnicodeDecodeError:
        abort(400)
    if request.environ.get('HTTP_X_DONT_DECODE'):
        request.charset = None
    request.referer = request.environ.get('HTTP_REFERER')
    request.user_agent = request.environ.get('HTTP_USER_AGENT')
    request.parsed_agent = Agent.parse(request.user_agent)
    request.fullpath = request.environ.get('FULLPATH', request.path)
    request.fullurl = (request.host_url + request.fullpath)
    request.port = request.environ.get('request_port')
    if_modified_since = request.environ.get('HTTP_IF_MODIFIED_SINCE')
    if if_modified_since:
        request.if_modified_since = read_http_date(if_modified_since)
    else:
        request.if_modified_since = None
    self.fix_cookie_header()
    self.pre()
