AsyncRead/AsyncWrite/Stream for `multipart/form-data` rfc7578
Stream
Preparse headers of part
```rust let body = Body::wrap_stream(stream); let mut form = FormData::new("----WebKitFormBoundaryWLHCs9qmcJJoyjKR", body);
while let Some(mut field) = form.trynext().await? { assert!(!field.consumed()); asserteq!(field.length, 0);
match field.index {
Some(0) => {
assert_eq!(field.name, "_method");
assert_eq!(field.filename, None);
assert_eq!(field.content_type, None);
}
Some(1) => {
assert_eq!(field.name, "profile[blog]");
assert_eq!(field.filename, None);
assert_eq!(field.content_type, None);
}
Some(2) => {
assert_eq!(field.name, "profile[public_email]");
assert_eq!(field.filename, None);
assert_eq!(field.content_type, None);
}
Some(3) => {
assert_eq!(field.name, "profile[interests]");
assert_eq!(field.filename, None);
assert_eq!(field.content_type, None);
}
Some(4) => {
assert_eq!(field.name, "profile[bio]");
assert_eq!(field.filename, None);
assert_eq!(field.content_type, None);
}
Some(5) => {
assert_eq!(field.name, "media");
assert_eq!(field.filename, Some(String::new()));
assert_eq!(field.content_type, Some(mime::APPLICATION_OCTET_STREAM));
}
Some(6) => {
assert_eq!(field.name, "commit");
assert_eq!(field.filename, None);
assert_eq!(field.content_type, None);
}
_ => {}
}
let buffer = field.bytes().await?;
match field.index {
Some(0) => {
assert_eq!(buffer, "put");
}
Some(1) => {
assert_eq!(buffer, "");
}
Some(2) => {
assert_eq!(buffer, "");
}
Some(3) => {
assert_eq!(buffer, "");
}
Some(4) => {
assert_eq!(buffer, "hello\r\n\r\n\"quote\"");
}
Some(5) => {
assert_eq!(buffer, "");
}
Some(6) => {
assert_eq!(buffer, "Save");
}
_ => {}
}
assert_eq!(field.length, buffer.len() as u64);
assert!(field.consumed());
}
let state = form.state(); let state = state.trylock().maperr(|e| anyhow!(e.to_string()))?;
asserteq!(state.eof(), true); asserteq!(state.total(), 7); ```
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.