def _get_request_uri(environ):
    """Returns REQUEST_URI from WSGI environ

    Environ variable REQUEST_URI is not specified in PEP 333 but provided
    by most servers. This function tries the server generated value and
    fallbacks to reconstruction from variables specified in PEP 333.
    """

    try:
        rv = environ['REQUEST_URI']
    except KeyError:
        parts = [environ.get('SCRIPT_NAME', ''),
                 environ.get('PATH_INFO', '')]
        query = environ.get('QUERY_STRING')
        if query:
            parts.extend(['?', query])
        rv = ''.join(parts)
    return rv