Detect content types when browsing files - #224
Merged
Merged
Conversation
There was a problem hiding this comment.
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/archivesto 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use
magicas 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 remaintext/plain.\n\nUpdatearchivesto v0.4.0 and remove the extensionless ZIP filename workaround so archives are detected from content.