Add support for Content-Disposition response header field
PR to fix #21.
That looks good. But rather than the argument being the entire value of the Content-Disposition header, should it be the value of the filename? I know I would probably have to constantly consult the docs to see what the correct format is. 😅
i.e. would this be a more ergonomic and nicer API:
cgi::binary_response(200, "application/octet-stream", "filename.bin", vec![1, 2]);
If the argument is set, then the header value can be constructed from format!("attachment; filename={}", …).
Is this possible? Desireable?
That is a nicer API, but it would miss the other parts of the Content-Disposition header field's scope (display inline or as attachment, multipart/forms).
Would it be an option to accept both in the same argument? I.e. a filename or the full header string starting with "content-disposition: " in case someone needs it. Using something like this:
if let Some(cd) = content_disposition {
const HEADER_NAME: &str = "content-disposition: ";
let arg_cleaned: String = cd.to_lowercase().trim().to_string();
let cd = if arg_cleaned.starts_with(HEADER_NAME) {
arg_cleaned.split(HEADER_NAME).collect::<String>()
} else {
format!("attachment; filename=\"{}\"", cd)
};
response = response.header(http::header::CONTENT_DISPOSITION, cd);
}
The same could be done for Content-Type.