Skip to content

Detect content types when browsing files - #224

Merged
andrew merged 2 commits into
mainfrom
magic-integration
Aug 1, 2026
Merged

Detect content types when browsing files#224
andrew merged 2 commits into
mainfrom
magic-integration

Conversation

@andrew

@andrew andrew commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Use magic as the content-type fallback for browsed files without a known path mapping. The handler peeks at most 512 bytes and replays them while streaming the file, and only promotes PNG, JPEG, GIF, and PDF to registered MIME types. Active web formats remain text/plain.\n\nUpdate archives to v0.4.0 and remove the extensionless ZIP filename workaround so archives are detected from content.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the file-browsing handler by adding content-based MIME detection for files that don’t have a reliable extension/path mapping, while keeping potentially active web formats served as text/plain. It also updates the archive handling dependency so extensionless archives can be detected from content instead of relying on filename workarounds.

Changes:

  • Add a 512-byte prefix peek and magic-based content-type fallback for unknown-path browsed files (promoting PNG/JPEG/GIF/PDF only).
  • Update github.com/git-pkgs/archives to v0.4.0 and remove the extensionless-zip filename workaround in archive opening.
  • Expand browse tests and add a micro-benchmark for content-type detection.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/server/browse.go Adds prefix-peek + magic fallback for MIME detection and removes archive filename extension workaround.
internal/server/browse_test.go Adds coverage for extensionless/binary sniffing behavior and updates archive behavior tests.
internal/server/browse_bench_test.go Adds a benchmark for the new content-type detection paths.
go.mod Updates archives to v0.4.0 and adds magic dependency.
go.sum Updates checksums for the new/updated dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/server/browse.go
@andrew
andrew merged commit a7cad78 into main Aug 1, 2026
8 checks passed
@andrew
andrew deleted the magic-integration branch August 1, 2026 10:26
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