Skip to content

Conversation

neilberkman
Copy link
Contributor

@neilberkman neilberkman commented Aug 1, 2025

Fix Content-Type headers in IIIF responses

The library was not setting Content-Type headers, causing them to fall back to application/octet-stream. This fix ensures proper content-type headers are set based on the requested output format (image/jpeg, image/png, etc).

  • Fixes response header application from DataRequest callbacks
  • Adds automatic content-type detection based on output format
  • Includes comprehensive tests for all send methods

- Apply response_headers from DataRequest to all send methods (send_buffered, send_stream, send_temporary_file)
- Auto-detect proper content-type based on output format instead of defaulting to application/octet-stream
- Add format_to_content_type mapping for common image formats (JPEG, PNG, WebP, TIFF, etc.)
- Preserve custom content-type headers when explicitly set in DataRequest.response_headers
- Add comprehensive tests for content-type detection across all send methods
- Add test plug for custom content-type scenarios

This fixes the issue where IIIF images were being served with incorrect
content-type headers causing browsers to download files instead of displaying them inline.
Copy link
Member

@dersmon dersmon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again! I had only one small suggestion.

Comment on lines 396 to 398
# Use the requested format for content-type (since that's what we're delivering)
conn = put_resp_content_type_from_format(conn, format)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add these calls between line 329 and 330, before it branches off to the different response types?

As suggested in PR review, move the put_resp_content_type_from_format call
to occur before the cond statement that branches into different response
methods. This ensures consistent content-type handling across all response
paths (send_buffered, send_temporary_file, and send_stream).
@dersmon dersmon merged commit 820a4d7 into dainst:main Aug 1, 2025
1 check passed
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.

2 participants