Repository navigation
Allow forcing the download of specific file extensions. - #184
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new feature to force file downloads based on specified extensions by setting a Content-Disposition header.
- Introduce a
ForceDownloadExtensionsfield and CLI flag for configuring extensions. - Implement
ShouldForceDownloadinserver.goand apply it inserveFileto set the download header. - Add detailed documentation and update CLI references.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/server/server.go | Added ForceDownloadExtensions field and ShouldForceDownload method. |
| internal/server/handlers.go | Integrated ShouldForceDownload into serveFile, setting Content-Disposition. |
| docs/force-download.md | New guide for using --force-download-extensions. |
| docs/directory-listing.md | Clarified that directory-rendered Markdown isn’t affected. |
| docs/README.md | Linked to the new force-download documentation. |
| app.go | Registered the force-download-extensions flag. |
| README.md | Documented the new CLI flag in the main usage guide. |
Comments suppressed due to low confidence (3)
internal/server/server.go:106
- Add unit tests for ShouldForceDownload covering edge cases (no extensions configured, extensions with/without leading dot, mixed case) to ensure expected behavior.
func (s *Server) ShouldForceDownload(filename string) bool {
internal/server/handlers.go:302
- handlers.go uses fmt.Sprintf and filepath.Base but fmt and path/filepath are not imported. Add the missing imports for "fmt" and "path/filepath".
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%q", filename))
docs/force-download.md:29
- [nitpick] Verify that environment variable support is implemented for this feature or clarify in the docs if setting the flag via environment variables requires additional setup.
export FILE_SERVER_FORCE_DOWNLOAD_EXTENSIONS=jpg,pdf,zip
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.
Added support for forcing file downloads via Content-Disposition header.
This feature allows specifying extensions that should always be downloaded instead of displayed in browser using the new
--force-download-extensionsflag.Documentation includes implementation details, usage examples, and limitations regarding markdown rendering.