Skip to content

Commit 5152287

Browse files
committed
more multipart progress...
1 parent 676cdef commit 5152287

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

src/body.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl Body {
422422

423423
/// Get the file name of the `Body`, if it's set.
424424
pub fn file_name(&self) -> Option<&str> {
425-
self.file_name.as_ref().map(|s| s.as_str())
425+
self.file_name.as_deref()
426426
}
427427

428428
/// Set the file name of the `Body`.

src/multipart/entry.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use crate::{Body, Error, Mime};
1+
use crate::{Body, Mime};
22

3-
use std::convert::TryFrom;
43
use std::fmt::{self, Debug};
54
// use std::path::Path;
65
use std::pin::Pin;
@@ -139,16 +138,14 @@ impl Into<Body> for Entry {
139138
}
140139
}
141140

142-
impl TryFrom<Body> for Entry {
143-
type Error = Error;
144-
145-
fn try_from(body: Body) -> Result<Self, Self::Error> {
141+
impl From<Body> for Entry {
142+
fn from(body: Body) -> Self {
146143
match body.file_name.clone() {
147-
Some(name) => Ok(Self { body, name }),
148-
None => Err(Error::from_str(
149-
500,
150-
"Missing file_name on Body to convert to Multipart Entry",
151-
)),
144+
Some(name) => Self { body, name },
145+
None => Self {
146+
body,
147+
name: String::new(),
148+
},
152149
}
153150
}
154151
}

src/multipart/mod.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,28 @@ impl Stream for Multipart {
188188
// }
189189
// }
190190

191-
struct BufReader<R: AsyncRead> {
191+
// We need AsRef<[u8]> on BufReader for TryStreamExt (into_async_read) so... wrap and patch it in ourselves, for now.
192+
#[doc(hidden)]
193+
#[derive(Debug)]
194+
pub struct BufReader<R: AsyncRead> {
192195
inner: io::BufReader<R>,
193196
}
194197

198+
#[doc(hidden)]
195199
impl<R: AsyncRead> BufReader<R> {
200+
#[allow(missing_doc_code_examples)]
201+
#[doc(hidden)]
196202
pub fn new(inner: R) -> Self {
197203
Self {
198204
inner: io::BufReader::new(inner),
199205
}
200206
}
201207
}
202208

209+
#[doc(hidden)]
203210
impl<R: AsyncRead> AsRef<[u8]> for BufReader<R> {
211+
#[allow(missing_doc_code_examples)]
212+
#[doc(hidden)]
204213
fn as_ref(&self) -> &[u8] {
205214
self.inner.buffer()
206215
}
@@ -210,11 +219,13 @@ impl From<Multipart> for Body {
210219
fn from(multipart: Multipart) -> Self {
211220
let stream = multipart.map(|maybe_entry| {
212221
maybe_entry
213-
.map(|entry| BufReader::new(entry))
222+
.map(BufReader::new)
214223
.map_err(|err| {
215-
std::io::Error::new(std::io::ErrorKind::Other, err.to_string().to_owned())
224+
std::io::Error::new(std::io::ErrorKind::Other, err.to_string())
216225
})
217226
});
218-
Body::from_reader(io::BufReader::new(stream.into_async_read()), None)
227+
let mut body = Body::from_reader(io::BufReader::new(stream.into_async_read()), None);
228+
body.set_mime(mime::MULTIPART_FORM);
229+
body
219230
}
220231
}

0 commit comments

Comments
 (0)