-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add a File type to axum-extra #2768
Comments
Sounds like a neat idea, I would call this pub struct Attachment<T> {
inner: T,
filename: Option<HeaderValue>,
content_type: Option<HeaderValue>,
}
impl<T: IntoResponse> Attachment<T> {
pub fn new(inner: T) -> Self { /* set other fields to None */ }
pub fn filename<H: TryInto<HeaderValue>>(self, value: H) -> Self { /* ... */ }
pub fn content_type<H: TryInto<HeaderValue>>(self, value: H) -> Self { /* ... */ }
}
impl<T: IntoResponse> IntoResponse for Attachment<T> { /* ... */ } I suppose if the
|
The name change sounds good. Nice that hyper sets the content-length header, that would make this type easier to work with. Your public API looks handy, however why is the filename an |
So the reason The impl will be a little bit more involved as |
Ahh I understand, thanks for your clarification. I have written a PR for this. Now that I think about it, would it be useful to make the Also how should the |
I think logging it with tracing and setting the field to |
Feature Request
Would it be useful to add a response type for a file in Axum? This response type would set headers like Content-Type, Content-Disposition and Content-Length. This could be a
File
type just like theHtml
and other types but one that is more generic. I would suppose that thisFile
type would live in theaxum-extra
crate.Motivation
I think this would make Axum more user-friendly. Currently the way to respond with a file is through:
Html
,JavaScript
,Css
andWasm
types.Body
type and setting the right headers.Proposal
I was thinking of something like this:
This does mean that axum-extra has to export the
Mime
type somewhere. Also this implementation could be too simple. Any feedback would be appreciated!Alternatives
I already saw this issue which is kind of the same but also not really. A multipart response type seems more specific than the
File
type for me. #2624The text was updated successfully, but these errors were encountered: