mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-26 17:30:27 -04:00
refac(images): request an unencoded body when fetching remote chat images (#29623)
The remote chat-image fetch now asks for an identity-encoded response and skips one that comes back content-encoded. An image whose host stores and echoes a `Content-Encoding` regardless of what the client asks for (an S3 or MinIO object uploaded with that metadata) is no longer inlined; the message is forwarded with the original URL instead, the same way an unreachable image already behaves.
This commit is contained in:
@@ -75,9 +75,16 @@ async def get_image_base64_from_url(url: str, user=None) -> Optional[str]:
|
||||
# rebinding DNS answer that passed validate_url cannot reach an internal address.
|
||||
async with get_ssrf_safe_session() as session:
|
||||
async with session.get(
|
||||
url, ssl=AIOHTTP_CLIENT_SESSION_SSL, allow_redirects=AIOHTTP_CLIENT_ALLOW_REDIRECTS
|
||||
url,
|
||||
ssl=AIOHTTP_CLIENT_SESSION_SSL,
|
||||
allow_redirects=AIOHTTP_CLIENT_ALLOW_REDIRECTS,
|
||||
headers={'Accept-Encoding': 'identity'},
|
||||
) as response:
|
||||
response.raise_for_status()
|
||||
# Accept-Encoding is only a request; the sender can still compress and pick our decompressed size.
|
||||
encodings = response.headers.getall('Content-Encoding', ())
|
||||
if any(encoding.lower() not in ('', 'identity') for encoding in encodings):
|
||||
return None
|
||||
image_data = bytearray()
|
||||
total = 0
|
||||
async for chunk in response.content.iter_chunked(64 * 1024):
|
||||
|
||||
Reference in New Issue
Block a user