Skip to content

Allow forcing the download of specific file extensions. - #184

Merged
patrickdappollonio merged 3 commits into
masterfrom
force-download
May 18, 2025
Merged

patrickdappollonio merged 3 commits into
masterfrom
force-download

Conversation

@patrickdappollonio

@patrickdappollonio patrickdappollonio commented May 18, 2025 •

Copy link
Copy Markdown
Owner

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-extensions flag.

Documentation includes implementation details, usage examples, and limitations regarding markdown rendering.

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 adds a new feature to force file downloads based on specified extensions by setting a Content-Disposition header.

  • Introduce a ForceDownloadExtensions field and CLI flag for configuring extensions.
  • Implement ShouldForceDownload in server.go and apply it in serveFile to 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

Comment thread internal/server/server.go Resolved
@patrickdappollonio
patrickdappollonio merged commit f5a18b7 into master May 18, 2025
@patrickdappollonio
patrickdappollonio deleted the force-download branch May 18, 2025 22:44
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