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

Conversation

hexboy
Copy link

@hexboy hexboy commented Apr 13, 2025

Issue

The endpoint /files/{date}/{file_name} fails with an AttributeError when the Accept header is not provided (e.g., in a simple curl request without headers):

AttributeError: 'NoneType' object has no attribute 'lower'

This occurs because the code assumes accept is always present but does not handle cases where it is None.

Changes

  • Added a check for accept is not None before processing the header.
  • Made file extension checks from file name if accept is None.
  • set ext = None to handle missing/invalid headers gracefully.

Impact

  • Fixes: Simple requests (e.g., direct browser access or curl without headers) now work instead of crashing.
  • Backward-compatible: Existing requests with valid Accept headers remain unaffected.

Testing

Verified with:

# Without Accept header (previously crashed, now returns the original file)
curl --location 'http://127.0.0.1:8888/files/2025-04-14/abe30891-4656-48de-8cab-fd0d25ea6a34-0.png'  \
  -H 'Accept: '

# With Accept header (unchanged behavior)
curl --location 'http://127.0.0.1:8888/files/2025-04-14/abe30891-4656-48de-8cab-fd0d25ea6a34-0.png' \
  -H 'Accept: image/webp'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant