This commit is contained in:
Martin Algesten
2018-07-01 19:01:35 +02:00
parent 8decd8e489
commit 4fbcc2246f

View File

@@ -14,6 +14,9 @@ use super::SerdeValue;
#[cfg(feature = "json")] #[cfg(feature = "json")]
use serde_json; use serde_json;
/// The different kinds of bodies to send.
///
/// *Internal API*
pub enum Payload { pub enum Payload {
Empty, Empty,
Text(String, String), Text(String, String),
@@ -40,6 +43,9 @@ impl Default for Payload {
} }
} }
/// Payloads are turned into this type where we can hold both a size and the reader.
///
/// *Internal API*
pub struct SizedReader { pub struct SizedReader {
pub size: Option<usize>, pub size: Option<usize>,
pub reader: Box<dyn Read + 'static>, pub reader: Box<dyn Read + 'static>,
@@ -81,6 +87,7 @@ impl Payload {
} }
} }
/// Helper to send a body, either as chunked or not.
pub fn send_body(mut body: SizedReader, do_chunk: bool, stream: &mut Stream) -> IoResult<()> { pub fn send_body(mut body: SizedReader, do_chunk: bool, stream: &mut Stream) -> IoResult<()> {
if do_chunk { if do_chunk {
let mut chunker = chunked_transfer::Encoder::new(stream); let mut chunker = chunked_transfer::Encoder::new(stream);