def filter_request(req):
    """
    Extract request attributes from the request metadata
    """

    res = {'path': req['environ']['PATH_INFO'],
           'method': req['environ']['REQUEST_METHOD'],
           'user-agent': req['environ']['HTTP_USER_AGENT'],
           'remote_addr': req['environ']['REMOTE_ADDR'],
           'remote_port': req['environ']['REMOTE_PORT']
           }
    if req['environ'].get('CONTENT_TYPE'):
        res['content_type'] = req['environ']['CONTENT_TYPE']
    return res