-
Notifications
You must be signed in to change notification settings - Fork 201
Open
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-hardCall for participation: Experience needed to fix: Hard / a lotCall for participation: Experience needed to fix: Hard / a lot
Description
We've heard from several users who want to use ServeDir
(or ServeFile
) with files that are embedded in the binary, perhaps using rust-embed. By using ServeDir
they'd get a lot for free such as finding the file from the path, range requests, pre-compressed files, etc.
That isn't possible today since ServeDir
is hardcoded to always fetch files from the filesystem. I've been thinking that it could be solved by making a "backend" trait that tells ServeDir
how to open files and get metadata. Something like:
#[async_trait]
pub trait Backend {
type File: AsyncRead + AsyncSeek;
type Metadata: FileMetadata;
async fn open_file(&self, path: Path) -> io::Result<Self::File>;
async fn metadata(&self, path: Path) -> io::Result<Self::Metadata>;
}
// we need a trait here because users cannot construct `std::fs::Metadata`
pub trait Metadata {
// whatever methods we need
}
Then tower-http could provide a default backend that uses the file system but allow others to write their own.
This should be possible without breaking changes so not adding it to the 0.4 milestone.
Nehliin, Folyd, akashgurava, sandreae, ttys3 and 9 more
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.E-hardCall for participation: Experience needed to fix: Hard / a lotCall for participation: Experience needed to fix: Hard / a lot