コード例 #1
0
ファイル: http.py プロジェクト: thelucyclub/meme-server
def get(url, **kwargs):
    if 'proxy_url' in config:
        res = requests.get(config['proxy_url'], params={'url': url}, **kwargs)
    else:
        res = requests.get(url, **kwargs)

    if 'content-length' not in res.headers:
        raise exceptions.BadRequest(f'{url} is missing `content-length` header')

    if int(res.headers.get('content-length', 0)) > MAX_FILE_SIZE:
        raise exceptions.BadRequest(f'content-length may not exceed {MAX_FILE_SIZE} bytes')

    return res
コード例 #2
0
ファイル: http.py プロジェクト: unwizzed/Shinobu-image-gen
def get_image(url, **kwargs):
    try:
        raw = get_content_raw(url, **kwargs)
        return Image.open(BytesIO(raw))
    except OSError:
        raise exceptions.BadRequest(
            'An invalid image was provided! Check the URL and try again.')
コード例 #3
0
ファイル: http.py プロジェクト: unwizzed/Shinobu-image-gen
def get(url, **kwargs):
    if config.get('new_proxy', False):
        proxies = config.get('proxies', {})
        res = requests.get(url, proxies=proxies, **kwargs)
    else:
        if 'proxy_url' in config:
            res = requests.get(config['proxy_url'],
                               params={'url': url},
                               headers={'Authorization': config['proxy_auth']},
                               **kwargs)
        else:
            res = requests.get(url, **kwargs)

    if 'content-length' not in res.headers:
        raise exceptions.BadRequest(
            f'{url} is missing `content-length` header')

    if int(res.headers.get('content-length', 0)) > MAX_FILE_SIZE:
        raise exceptions.BadRequest(
            f'content-length may not exceed {MAX_FILE_SIZE} bytes')

    return res
コード例 #4
0
ファイル: http.py プロジェクト: Lifeismana/imgen
def get(url, **kwargs):
    if config.get("new_proxy", False):
        proxies = config.get("proxies", {})
        res = requests.get(url, proxies=proxies, **kwargs)
    else:
        if "proxy_url" in config:
            res = requests.get(
                config["proxy_url"],
                params={"url": url},
                headers={"Authorization": config["proxy_auth"]},
                **kwargs,
            )
        else:
            res = requests.get(url, **kwargs)

    if "content-length" not in res.headers:
        raise exceptions.BadRequest(f"{url} is missing `content-length` header")

    if int(res.headers.get("content-length", 0)) > MAX_FILE_SIZE:
        raise exceptions.BadRequest(
            f"content-length may not exceed {MAX_FILE_SIZE} bytes"
        )

    return res