pub struct StreamingResponse { /* private fields */ }Expand description
HTTP response with a streaming body.
Status and headers are available immediately. Consume the body via Self::bytes_stream
or buffer it with Self::collect.
§Examples
let client = Client::new("https://httpbin.org")?;
let mut stream = client.get("/stream/5").send_stream().await?;
while let Some(chunk) = stream.bytes_stream().next().await {
let chunk = chunk?;
println!("got {} bytes", chunk.len());
}Implementations§
Source§impl StreamingResponse
impl StreamingResponse
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
HTTP status code.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Returns true for 2xx status codes.
Sourcepub fn error_for_status(&self) -> Result<()>
pub fn error_for_status(&self) -> Result<()>
Returns an error if the status is not success (does not read the body).
Sourcepub fn bytes_stream(&mut self) -> &mut BodyStream
pub fn bytes_stream(&mut self) -> &mut BodyStream
Mutable reference to the response body stream.
Sourcepub async fn collect(self) -> Result<Response>
pub async fn collect(self) -> Result<Response>
Buffers the full body into a Response.
Respects ClientBuilder::max_response_bytes when
configured on the request or client (the limit is enforced on the underlying stream).
§Examples
let client = Client::new("https://api.example.com")?;
let buffered = client.get("/data").send_stream().await?.collect().await?;
let text = buffered.into_text()?;Sourcepub fn into_parts(self) -> (StatusCode, HeaderMap, BodyStream)
pub fn into_parts(self) -> (StatusCode, HeaderMap, BodyStream)
Splits into status, headers, and the body stream.
Sourcepub async fn stream_to_file(
self,
path: impl AsRef<Path>,
max_bytes: Option<u64>,
) -> Result<u64>
pub async fn stream_to_file( self, path: impl AsRef<Path>, max_bytes: Option<u64>, ) -> Result<u64>
Writes the response body to path, returning the number of bytes written.
Enforces max_bytes when set (same semantics as accumulate_stream).
Checks for success status before writing.
Sourcepub async fn read_sse_events(
self,
max_bytes: Option<u64>,
) -> Result<Vec<SseEvent>>
Available on crate feature sse only.
pub async fn read_sse_events( self, max_bytes: Option<u64>, ) -> Result<Vec<SseEvent>>
sse only.Buffers the stream (up to max_bytes) and parses text/event-stream events.
Sourcepub fn sse_events(self) -> SseEventStream
Available on crate feature sse only.
pub fn sse_events(self) -> SseEventStream
sse only.Incrementally parses SSE events from the response body as a Stream.
Respects max_bytes when set on the request (same as Self::collect).