Fix Gelbooru CDN — pass Referer header per-request
Shared client doesn't set Referer globally since it varies per domain. Now passed as per-request header so Gelbooru CDN doesn't return HTML captcha pages.
This commit is contained in:
parent
bfed81159b
commit
1807f77dd4
@ -159,12 +159,14 @@ async def download_image(
|
|||||||
|
|
||||||
log_connection(url)
|
log_connection(url)
|
||||||
|
|
||||||
|
req_headers = {"Referer": referer}
|
||||||
|
|
||||||
own_client = client is None
|
own_client = client is None
|
||||||
if own_client:
|
if own_client:
|
||||||
client = _get_shared_client()
|
client = _get_shared_client()
|
||||||
try:
|
try:
|
||||||
if progress_callback:
|
if progress_callback:
|
||||||
async with client.stream("GET", url) as resp:
|
async with client.stream("GET", url, headers=req_headers) as resp:
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
content_type = resp.headers.get("content-type", "")
|
content_type = resp.headers.get("content-type", "")
|
||||||
if "text/html" in content_type:
|
if "text/html" in content_type:
|
||||||
@ -179,7 +181,7 @@ async def download_image(
|
|||||||
data = b"".join(chunks)
|
data = b"".join(chunks)
|
||||||
local.write_bytes(data)
|
local.write_bytes(data)
|
||||||
else:
|
else:
|
||||||
resp = await client.get(url)
|
resp = await client.get(url, headers=req_headers)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
content_type = resp.headers.get("content-type", "")
|
content_type = resp.headers.get("content-type", "")
|
||||||
if "text/html" in content_type:
|
if "text/html" in content_type:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user