Skip to main content

http_type/body/
struct.rs

1use super::*;
2
3/// A single part of a `multipart/form-data` body.
4///
5/// A part carries the form field name declared by its `Content-Disposition`
6/// header, the file name of an uploaded file when the part is a file, the
7/// headers that belong to the part alone, and its raw content.
8///
9/// Storage is `pub(super)` (ยง17.14): a caller never touches the fields
10/// directly. The public read surface is the `try_get_*` family below,
11/// which follows the same `Option`-returning convention as
12/// [`crate::Request`] and [`crate::Response`] and therefore never fails
13/// loudly on a part that lacks an optional attribute.
14#[derive(Clone, Data, Debug, Default, Deserialize, DisplayDebug, Eq, New, PartialEq, Serialize)]
15pub struct BodyPart {
16    /// Form field name declared by the part `Content-Disposition` header.
17    #[get(pub(super))]
18    #[get_mut(pub(super))]
19    #[set(pub(super))]
20    pub(super) name: BodyPartName,
21    /// File name of an uploaded file, empty when the part is a plain field.
22    #[get(pub(super))]
23    #[get_mut(pub(super))]
24    #[set(pub(super))]
25    pub(super) file_name: BodyPartFileName,
26    /// Media type declared by the part `Content-Type` header.
27    #[get(pub(super))]
28    #[get_mut(pub(super))]
29    #[set(pub(super))]
30    pub(super) content_type: BodyPartContentType,
31    /// Headers carried by this part alone.
32    #[get(pub(super))]
33    #[get_mut(pub(super))]
34    #[set(pub(super))]
35    pub(super) headers: BodyPartHeaders,
36    /// Raw content of this part.
37    #[get(pub(super))]
38    #[get_mut(pub(super))]
39    #[set(pub(super))]
40    pub(super) data: BodyPartData,
41}
42
43/// Parser for `multipart/form-data` bodies.
44///
45/// Decodes a body into its parts using the boundary declared by the request
46/// `Content-Type` header, without depending on any external multipart crate.
47#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
48pub struct MultipartFormData;