pub fn encode_part_head(
boundary: &Boundary,
first: bool,
name: &str,
filename: Option<&str>,
content_type: Option<&str>,
out: &mut [u8],
) -> Result<usize, FormError>Expand description
Writes one part’s head into out without allocating: the delimiter
(with its leading CRLF unless first), the Content-Disposition line
with browser escaping, the optional Content-Type line, and the blank
line. Returns the bytes written.
After the last part’s data the caller writes the close delimiter:
Boundary::delimiter followed by --\r\n; for a body with no parts,
--, the boundary, and --\r\n.
§Errors
BufferTooSmall { needed } (nothing is written);
Syntax { EmptyName | ControlInHeader | AmbiguousQuote | InvalidContentType }.
§Examples
let b = form_net::Boundary::new(b"X")?;
let mut out = [0u8; 128];
let n = form_net::encode_part_head(&b, true, "a\"b", None, None, &mut out)?;
assert_eq!(&out[..n], b"--X\r\nContent-Disposition: form-data; name=\"a%22b\"\r\n\r\n");