import six


def get_body_from_env(env):
    """Exctracts request body from wsgi environment variable"""
    content_length = env.get('CONTENT_LENGTH')
    body = ''

    if content_length:  # detects None, 0 or '' values of CONTENT_LENGTH key
        length = int(content_length)
        body = env['wsgi.input'].read(length)
        env['wsgi.input'] = six.StringIO(body)

    return body