pub struct FetchStreamReader {
pub final_url: Url,
pub status_code: u16,
pub headers: Vec<(String, String)>,
pub response_time: Duration,
pub body_size: usize,
/* private fields */
}Expand description
A streaming HTTP response reader.
Read chunks from the body using the next_chunk method.
The stream automatically respects max_body_size. Can be converted into
a FetchResult via into_fetch_result.
§Examples
use crawlkit_engine::{CrawlConfig, HttpClient};
use url::Url;
let client = HttpClient::from_crawl_config(&CrawlConfig::default())?;
let url = Url::parse("https://example.com")?;
let mut reader = client.fetch_reader(&url).await?;
while let Some(chunk) = reader.next_chunk().await? {
// process chunk
}Fields§
§final_url: Url§status_code: u16§headers: Vec<(String, String)>§response_time: Duration§body_size: usizeImplementations§
Source§impl FetchStreamReader
impl FetchStreamReader
Sourcepub async fn next_chunk(&mut self) -> Result<Option<Vec<u8>>, CrawlError>
pub async fn next_chunk(&mut self) -> Result<Option<Vec<u8>>, CrawlError>
Reads the next chunk of the response body.
Returns Ok(Some(bytes)) if data is available, Ok(None) if the
stream is complete, or Err on error. Respects max_body_size.
§Errors
Returns CrawlError::RequestFailed on network errors.
Sourcepub async fn read_body(&mut self) -> Result<String, CrawlError>
pub async fn read_body(&mut self) -> Result<String, CrawlError>
Reads the entire remaining body into a String.
Convenience method that drains all remaining chunks and concatenates them into a single UTF-8 string (lossy conversion).
§Errors
Returns CrawlError::RequestFailed on network errors.
Sourcepub async fn into_fetch_result(self) -> Result<FetchResult, CrawlError>
pub async fn into_fetch_result(self) -> Result<FetchResult, CrawlError>
Converts this into a FetchResult by reading the full body.
Consumes the reader and returns the complete response including headers, status, and body content.
§Errors
Returns CrawlError::RequestFailed on network errors.
Auto Trait Implementations§
impl !RefUnwindSafe for FetchStreamReader
impl !Sync for FetchStreamReader
impl !UnwindSafe for FetchStreamReader
impl Freeze for FetchStreamReader
impl Send for FetchStreamReader
impl Unpin for FetchStreamReader
impl UnsafeUnpin for FetchStreamReader
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more