mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
multipart field is stream of bytes
This commit is contained in:
parent
790793f8a1
commit
e3f9345420
@ -11,5 +11,4 @@ path = "src/main.rs"
|
|||||||
env_logger = "*"
|
env_logger = "*"
|
||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
actix = "^0.3.1"
|
actix = "^0.3.1"
|
||||||
#actix-web = { git = "https://github.com/actix/actix-web.git" }
|
actix-web = { git = "https://github.com/actix/actix-web.git" }
|
||||||
actix-web = { path = "../../" }
|
|
||||||
|
@ -28,7 +28,7 @@ fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>>
|
|||||||
field.map_err(Error::from)
|
field.map_err(Error::from)
|
||||||
.map(|chunk| {
|
.map(|chunk| {
|
||||||
println!("-- CHUNK: \n{}",
|
println!("-- CHUNK: \n{}",
|
||||||
std::str::from_utf8(&chunk.0).unwrap());})
|
std::str::from_utf8(&chunk).unwrap());})
|
||||||
.fold((), |_, _| result::<_, Error>(Ok(()))))
|
.fold((), |_, _| result::<_, Error>(Ok(()))))
|
||||||
},
|
},
|
||||||
multipart::MultipartItem::Nested(mp) => {
|
multipart::MultipartItem::Nested(mp) => {
|
||||||
|
@ -114,6 +114,8 @@ fn index(req: HttpRequest) -> HttpResponse {
|
|||||||
|
|
||||||
## Multipart body
|
## Multipart body
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[WIP]
|
[WIP]
|
||||||
|
|
||||||
## Urlencoded body
|
## Urlencoded body
|
||||||
|
@ -377,10 +377,6 @@ pub struct Field {
|
|||||||
safety: Safety,
|
safety: Safety,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A field's chunk
|
|
||||||
#[derive(PartialEq, Debug)]
|
|
||||||
pub struct FieldChunk(pub Bytes);
|
|
||||||
|
|
||||||
impl Field {
|
impl Field {
|
||||||
|
|
||||||
fn new(safety: Safety, headers: HeaderMap,
|
fn new(safety: Safety, headers: HeaderMap,
|
||||||
@ -403,7 +399,7 @@ impl Field {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Stream for Field {
|
impl Stream for Field {
|
||||||
type Item = FieldChunk;
|
type Item = Bytes;
|
||||||
type Error = MultipartError;
|
type Error = MultipartError;
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
||||||
@ -522,7 +518,7 @@ impl InnerField {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll(&mut self, s: &Safety) -> Poll<Option<FieldChunk>, MultipartError> {
|
fn poll(&mut self, s: &Safety) -> Poll<Option<Bytes>, MultipartError> {
|
||||||
if self.payload.is_none() {
|
if self.payload.is_none() {
|
||||||
return Ok(Async::Ready(None))
|
return Ok(Async::Ready(None))
|
||||||
}
|
}
|
||||||
@ -554,7 +550,7 @@ impl InnerField {
|
|||||||
|
|
||||||
match res {
|
match res {
|
||||||
Async::NotReady => Async::NotReady,
|
Async::NotReady => Async::NotReady,
|
||||||
Async::Ready(Some(bytes)) => Async::Ready(Some(FieldChunk(bytes))),
|
Async::Ready(Some(bytes)) => Async::Ready(Some(bytes)),
|
||||||
Async::Ready(None) => {
|
Async::Ready(None) => {
|
||||||
self.eof = true;
|
self.eof = true;
|
||||||
match payload.readline().poll()? {
|
match payload.readline().poll()? {
|
||||||
@ -734,7 +730,7 @@ mod tests {
|
|||||||
|
|
||||||
match field.poll() {
|
match field.poll() {
|
||||||
Ok(Async::Ready(Some(chunk))) =>
|
Ok(Async::Ready(Some(chunk))) =>
|
||||||
assert_eq!(chunk.0, "test"),
|
assert_eq!(chunk, "test"),
|
||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
}
|
}
|
||||||
match field.poll() {
|
match field.poll() {
|
||||||
@ -757,7 +753,7 @@ mod tests {
|
|||||||
|
|
||||||
match field.poll() {
|
match field.poll() {
|
||||||
Ok(Async::Ready(Some(chunk))) =>
|
Ok(Async::Ready(Some(chunk))) =>
|
||||||
assert_eq!(chunk.0, "data"),
|
assert_eq!(chunk, "data"),
|
||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
}
|
}
|
||||||
match field.poll() {
|
match field.poll() {
|
||||||
|
Loading…
Reference in New Issue
Block a user