Skip to content

Fix: Handle missing or empty Accept header in /files/{date}/{file_name} endpoint #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions fooocusapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ async def get_output(date: str, file_name: str, accept: str = Header(None)):
Get a specific output by its ID.
"""
accept_formats = ('png', 'jpg', 'jpeg', 'webp')
try:
_, ext = accept.lower().split("/")

if accept is not None:
try:
_, ext = accept.lower().split("/")
if ext not in accept_formats:
ext = None
except ValueError:
ext = None
else:
ext = file_name.split('.')[-1]
if ext not in accept_formats:
ext = None
except ValueError:
ext = None

if not file_name.endswith(accept_formats):
return Response(status_code=404)
Expand Down