Skip to content

sniff magic bytes for application/octet-stream to select correct previewer#1678

Open
badnikhil wants to merge 1 commit into
foss42:mainfrom
badnikhil:resolve-issue-1382
Open

sniff magic bytes for application/octet-stream to select correct previewer#1678
badnikhil wants to merge 1 commit into
foss42:mainfrom
badnikhil:resolve-issue-1382

Conversation

@badnikhil
Copy link
Copy Markdown
Contributor

@badnikhil badnikhil commented Apr 27, 2026

PR Description

This PR sniffs the first bytes of the response body using lookupMimeType from the mime package (already a transitive dependency via dio and share_plus) to detect the true format and route it to the correct previewer. The mime package is also added as a direct dependency to make the usage explicit.

The sniffing only applies when the declared type is exactly application/octet-stream and falls back gracefully if the format cannot be identified.
Sniffing is kept in the Previewer widget rather than the model layer because the sniffed type is a local rendering hint only, and i think moving it to the model would create an inconsistency between the persisted headers (which correctly reflect what the server sent) and the mediaType getter.

Related Issues

Checklist

  • I have gone through the contributing guide
  • I have updated my branch and synced it with project main branch before making this PR
  • I am using the latest Flutter stable branch (run flutter upgrade and verify)
  • I have run the tests (flutter test) and all tests are passing

Added/updated tests?

We encourage you to add relevant test cases.

  • Yes
  • No, and this is why: The fix delegates entirely to mime's lookupMimeType which is well-tested upstream.Also , the approach first needs to be reviewed.

OS on which you have developed and tested the feature?

  • Windows
  • macOS
  • Linux

@badnikhil badnikhil marked this pull request as ready for review April 27, 2026 21:27
@badnikhil badnikhil changed the title fix: sniff magic bytes for application/octet-stream to select correct… sniff magic bytes for application/octet-stream to select correct previewer Apr 27, 2026
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.

Previewer fallback based on magic bytes

1 participant