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<(), Error>
pub fn error_for_status(&self) -> Result<(), Error>
Returns an error if the status is not success (does not read the body).
Sourcepub fn bytes_stream(
&mut self,
) -> &mut Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send + Sync>>
pub fn bytes_stream( &mut self, ) -> &mut Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send + Sync>>
Mutable reference to the response body stream.
Sourcepub async fn collect(self) -> Result<Response, Error>
pub async fn collect(self) -> Result<Response, Error>
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, Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send + Sync>>)
pub fn into_parts( self, ) -> (StatusCode, HeaderMap, Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send + Sync>>)
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, Error>
pub async fn stream_to_file( self, path: impl AsRef<Path>, max_bytes: Option<u64>, ) -> Result<u64, Error>
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StreamingResponse
impl !RefUnwindSafe for StreamingResponse
impl Send for StreamingResponse
impl Sync for StreamingResponse
impl Unpin for StreamingResponse
impl UnsafeUnpin for StreamingResponse
impl !UnwindSafe for StreamingResponse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more