consider supporting custom mime type in serve_dir?

Open
#500 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

Start in tower-http/src/services/fs/serve_dir/open_file.rs at the existing mime_guess handling referenced by the issue. Trace how serve_dir opens files and determine the callback shape and precedence over the hardcoded MIME mapping. Done means callers can optionally provide custom extension-to-MIME mappings while existing behavior remains unchanged.

Written by the indexing model from the issue text.

Description

  • I have looked for existing issues (including closed) about this

Feature Request

current mime_guess is a hardcoded list.

taking a callback to optionally allow mapping certain file exts to something other than the hardcoded list would be helpful

Motivation

some types are missed in the mime_guess, and sometimes people may want to intentionally override the mime for well known file types

Proposal

take a callback and if it's set, preferred over here https://github.com/tower-rs/tower-http/blob/main/tower-http/src/services/fs/serve_dir/open_file.rs#L76

Alternatives
Dominant language
Rust
Stars
913
Forks
231
Avg merge
1d 20h
Merged PRs (30d)
8

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tower-rs/tower-http

All issues in tower-rs/tower-http

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.