-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default content-type for StaticFiles #1397
Comments
maybe one could provide a default content type via Rocket.toml? although i don't know how much of that would change with #852 |
There is no way to set a default impl StaticFiles {
pub fn default_content_type<C>(mut self, content_type: C) -> Self
where C: Into<Option<ContentType>>
{
self.default_content_type = content_type.into();
self
}
}
I would accept a PR implementing this API. It's unfortunate that |
@igalic With #852 implemented, you could parse your own # Rocket.toml
default_content_type = "application/json" #[derive(Deserialize)]
struct MyAppConfig {
default_content_type: ContentType
}
let config: MyAppConfig = Config::default().extract()?;
rocket::ignite().mount("/", StaticFiles::from(...).default(config.default_content_type)); |
Accepted, and moving to tracking in #95. |
Rocket version:
os version: OSX Catalina (10.15.6)
When using
StaticFiles
to serve content, it relies onContentType::from_extension
to generate the content-type header for a response. If a file does not have an extension, no content-type will be set. I'd like to know if there is a way to set a default content-type, or if that would be a useful feature to add. I'm willing to open a PR for the feature if there is a likely chance it will be accepted.To reproduce: serve a file without an extension using
rocket_contrib::serve::StaticFiles
Assuming there is no existing way to do this, I'd be curious about maintainers' ideas of how to solve this. I'd be happy defaulting to
text/plain
, and including it as an option in the existingOptions
bitmask. However, others might want the ability to set it to a specific content-type, liketext/html
or something else, and in that case I don't have a great idea for a design.The text was updated successfully, but these errors were encountered: