pub struct HttpChunkResponse<'r, R> {
pub reader: Pin<&'r mut R>,
pub status: StatusCode,
pub chunk_size: usize,
pub max_age: Option<u32>,
pub cache_private: Option<bool>,
pub headers: Option<Vec<HttpHeader>>,
pub pace: Option<BodyPace>,
}Expand description
Represents a chunked HTTP response for streaming large bodies of data.
This is used when the response body is too large to fit in memory or is generated on-the-fly.
Fields§
§reader: Pin<&'r mut R>A pinned, mutable reference to an async reader that provides the body data.
status: StatusCodeThe status of the response. Defaults to 200 OK.
chunk_size: usizeThe suggested size for each data chunk. Defaults to DEFAULT_BUF_SIZE.
max_age: Option<u32>Cache control max-age setting for the response.
cache_private: Option<bool>Cache control privacy setting for the response.
headers: Option<Vec<HttpHeader>>Additional headers to include in the response.
pace: Option<BodyPace>How fast the body is sent, where that is limited.
Implementations§
Source§impl<'r, R> HttpChunkResponse<'r, R>
impl<'r, R> HttpChunkResponse<'r, R>
Sourcepub fn new(r: &'r mut R) -> Self
pub fn new(r: &'r mut R) -> Self
Creates a new HttpChunkResponse with a given reader and default settings.
Sourcepub fn get_response_header(&self) -> Result<ResponseHeader>
pub fn get_response_header(&self) -> Result<ResponseHeader>
Builds the ResponseHeader for the streamed response.
The body is framed by Content-Length when the custom headers give
one, and by Transfer-Encoding: chunked otherwise. Both at once is
not a valid message, and that is what a streamed file used to get:
its length was known and sent, and chunked was added regardless.
Sourcepub async fn send(self, session: &mut Session) -> Result<usize>
pub async fn send(self, session: &mut Session) -> Result<usize>
Streams the data from the reader to the client as a chunked response.
Reads data from the reader in chunks and sends each chunk to the client until
the reader is exhausted.
Sourcepub async fn send_with_header(
self,
session: &mut Session,
header: ResponseHeader,
) -> Result<usize>
pub async fn send_with_header( self, session: &mut Session, header: ResponseHeader, ) -> Result<usize>
Sends the body under header: the one get_response_header builds,
with whatever the caller has added to it.