mirror of
https://github.com/0xMassi/webclaw.git
synced 2026-07-24 07:31:01 +02:00
style: cargo fmt
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1a5d3d8aaf
commit
124352e0b4
2 changed files with 33 additions and 13 deletions
|
|
@ -93,15 +93,33 @@ impl Response {
|
||||||
let status = resp.status().as_u16();
|
let status = resp.status().as_u16();
|
||||||
let url = resp.uri().to_string();
|
let url = resp.uri().to_string();
|
||||||
let headers = resp.headers().clone();
|
let headers = resp.headers().clone();
|
||||||
let body = resp.bytes().await.map_err(|e| FetchError::BodyDecode(e.to_string()))?;
|
let body = resp
|
||||||
Ok(Self { status, url, headers, body })
|
.bytes()
|
||||||
|
.await
|
||||||
|
.map_err(|e| FetchError::BodyDecode(e.to_string()))?;
|
||||||
|
Ok(Self {
|
||||||
|
status,
|
||||||
|
url,
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn status(&self) -> u16 { self.status }
|
fn status(&self) -> u16 {
|
||||||
fn url(&self) -> &str { &self.url }
|
self.status
|
||||||
fn headers(&self) -> &http::HeaderMap { &self.headers }
|
}
|
||||||
fn body(&self) -> &[u8] { &self.body }
|
fn url(&self) -> &str {
|
||||||
fn is_success(&self) -> bool { (200..300).contains(&self.status) }
|
&self.url
|
||||||
|
}
|
||||||
|
fn headers(&self) -> &http::HeaderMap {
|
||||||
|
&self.headers
|
||||||
|
}
|
||||||
|
fn body(&self) -> &[u8] {
|
||||||
|
&self.body
|
||||||
|
}
|
||||||
|
fn is_success(&self) -> bool {
|
||||||
|
(200..300).contains(&self.status)
|
||||||
|
}
|
||||||
|
|
||||||
fn text(&self) -> std::borrow::Cow<'_, str> {
|
fn text(&self) -> std::borrow::Cow<'_, str> {
|
||||||
String::from_utf8_lossy(&self.body)
|
String::from_utf8_lossy(&self.body)
|
||||||
|
|
@ -147,7 +165,12 @@ impl FetchClient {
|
||||||
let clients = variants
|
let clients = variants
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|v| {
|
.map(|v| {
|
||||||
crate::tls::build_client(v, config.timeout, &config.headers, config.proxy.as_deref())
|
crate::tls::build_client(
|
||||||
|
v,
|
||||||
|
config.timeout,
|
||||||
|
&config.headers,
|
||||||
|
config.proxy.as_deref(),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
|
@ -454,10 +477,7 @@ fn collect_variants(profile: &BrowserProfile) -> Vec<BrowserVariant> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a buffered Response into a FetchResult.
|
/// Convert a buffered Response into a FetchResult.
|
||||||
fn response_to_result(
|
fn response_to_result(response: Response, start: Instant) -> Result<FetchResult, FetchError> {
|
||||||
response: Response,
|
|
||||||
start: Instant,
|
|
||||||
) -> Result<FetchResult, FetchError> {
|
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
let final_url = response.url().to_string();
|
let final_url = response.url().to_string();
|
||||||
let headers = response.headers().clone();
|
let headers = response.headers().clone();
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ pub use browser::BrowserProfile;
|
||||||
pub use client::{BatchExtractResult, BatchResult, FetchClient, FetchConfig, FetchResult};
|
pub use client::{BatchExtractResult, BatchResult, FetchClient, FetchConfig, FetchResult};
|
||||||
pub use crawler::{CrawlConfig, CrawlResult, CrawlState, Crawler, PageResult};
|
pub use crawler::{CrawlConfig, CrawlResult, CrawlState, Crawler, PageResult};
|
||||||
pub use error::FetchError;
|
pub use error::FetchError;
|
||||||
|
pub use http::HeaderMap;
|
||||||
pub use proxy::{parse_proxy_file, parse_proxy_line};
|
pub use proxy::{parse_proxy_file, parse_proxy_line};
|
||||||
pub use sitemap::SitemapEntry;
|
pub use sitemap::SitemapEntry;
|
||||||
pub use http::HeaderMap;
|
|
||||||
pub use webclaw_pdf::PdfMode;
|
pub use webclaw_pdf::PdfMode;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue