pub struct ContentDisposition { /* private fields */ }Expand description
Represents the Content-Disposition header as defined in RFC 6266.
The Content-Disposition header is commonly used in HTTP responses to suggest a filename for a download, and to indicate whether the content should be displayed inline or as an attachment.
This implementation supports both regular parameters and the extended parameter syntax defined in RFC 5987 for internationalized filenames (filename*).
§Examples
use crate::http_value::{ContentDisposition, ContentDispositionType};
// Create an attachment disposition
let disposition = ContentDisposition::attachment("report.pdf");
assert_eq!(disposition.to_string(), "attachment; filename=\"report.pdf\"");
// Parse a Content-Disposition header with extended parameter syntax
let header = "attachment; filename*=UTF-8''%F0%9F%93%96.txt";
let parsed = ContentDisposition::parse(header).unwrap();
assert_eq!(parsed.filename().unwrap(), "馃摉.txt");Implementations§
Source§impl ContentDisposition
impl ContentDisposition
Sourcepub fn new(disposition_type: ContentDispositionType) -> ContentDisposition
pub fn new(disposition_type: ContentDispositionType) -> ContentDisposition
Sourcepub fn inline() -> ContentDisposition
pub fn inline() -> ContentDisposition
Creates a new ContentDisposition with type “inline”.
§Returns
A new ContentDisposition instance with type set to Inline
Sourcepub fn attachment<S>(filename: S) -> ContentDisposition
pub fn attachment<S>(filename: S) -> ContentDisposition
Sourcepub fn form_data<S, T>(name: S, filename: Option<T>) -> ContentDisposition
pub fn form_data<S, T>(name: S, filename: Option<T>) -> ContentDisposition
Sourcepub fn parse(
header: &str,
) -> Result<ContentDisposition, ContentDispositionError>
pub fn parse( header: &str, ) -> Result<ContentDisposition, ContentDispositionError>
Parses a Content-Disposition header string into a ContentDisposition.
This method supports both regular parameters and extended parameters using
the RFC 5987 syntax (e.g., filename*=UTF-8''file.txt).
§Arguments
header- The Content-Disposition header string
§Returns
Result<ContentDisposition, ContentDispositionError> containing either the parsed disposition
or an error message
§Examples
use crate::http_value::ContentDisposition;
// Regular parameter
let header = "attachment; filename=\"example.txt\"";
let disposition = ContentDisposition::parse(header).unwrap();
assert_eq!(disposition.filename().unwrap(), "example.txt");
// Extended parameter
let header = "attachment; filename*=UTF-8''%F0%9F%93%96.txt";
let disposition = ContentDisposition::parse(header).unwrap();
assert_eq!(disposition.filename().unwrap(), "馃摉.txt");Sourcepub fn disposition_type(&self) -> &ContentDispositionType
pub fn disposition_type(&self) -> &ContentDispositionType
Sourcepub fn set_disposition_type(&mut self, disposition_type: ContentDispositionType)
pub fn set_disposition_type(&mut self, disposition_type: ContentDispositionType)
Sourcepub fn filename(&self) -> Option<&str>
pub fn filename(&self) -> Option<&str>
Returns the filename, if any.
§Returns
An Option<&str> containing the filename or None if no filename is not set
Per RFC 6266, the filename* parameter has precedence over filename.
Sourcepub fn set_filename<S>(&mut self, filename: S)
pub fn set_filename<S>(&mut self, filename: S)
Sets the filename.
§Arguments
filename- The new filename
If the filename contains non-ASCII characters, it will automatically use the extended parameter format.
Sourcepub fn get_parameter(&self, name: &str) -> Option<&str>
pub fn get_parameter(&self, name: &str) -> Option<&str>
Sourcepub fn set_parameter<K, V>(&mut self, name: K, value: V)
pub fn set_parameter<K, V>(&mut self, name: K, value: V)
Sourcepub fn set_parameter_extended<K, C, L, V>(
&mut self,
name: K,
charset: C,
language: L,
value: V,
)
pub fn set_parameter_extended<K, C, L, V>( &mut self, name: K, charset: C, language: L, value: V, )
Sets an extended parameter value.
§Arguments
name- The parameter name (without the trailing ‘*’)charset- The character set (e.g., “UTF-8”)language- The language tag (can be empty)value- The parameter value
Sourcepub fn remove_parameter(&mut self, name: &str) -> bool
pub fn remove_parameter(&mut self, name: &str) -> bool
Sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
Converts the ContentDisposition to its string representation suitable for
use as an HTTP header value.
This method handles both regular parameters and extended parameters using the RFC 5987 syntax.
§Returns
A String containing the header value
Sourcepub fn parameters(&self) -> &HashMap<String, ParameterValue>
pub fn parameters(&self) -> &HashMap<String, ParameterValue>
Trait Implementations§
Source§impl Clone for ContentDisposition
impl Clone for ContentDisposition
Source§fn clone(&self) -> ContentDisposition
fn clone(&self) -> ContentDisposition
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContentDisposition
impl Debug for ContentDisposition
Source§impl PartialEq for ContentDisposition
impl PartialEq for ContentDisposition
impl StructuralPartialEq for ContentDisposition
Auto Trait Implementations§
impl Freeze for ContentDisposition
impl RefUnwindSafe for ContentDisposition
impl Send for ContentDisposition
impl Sync for ContentDisposition
impl Unpin for ContentDisposition
impl UnsafeUnpin for ContentDisposition
impl UnwindSafe for ContentDisposition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> ParamValue for T
impl<T> ParamValue for T
Source§fn clone_box(&self) -> Box<dyn ParamValue>
fn clone_box(&self) -> Box<dyn ParamValue>
ParamValue. Read moreSource§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any. Read moreSource§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any. Read more