MCPcopy Create free account
hub / github.com/apify/impit / new

Method new

impit/src/impit.rs:311–356  ·  view source on GitHub ↗

Creates a new [`Impit`] instance based on the options stored in the [`ImpitBuilder`] instance.

(config: ImpitBuilder<CookieStoreImpl>)

Source from the content-addressed store, hash-verified

309
310 /// Creates a new [`Impit`] instance based on the options stored in the [`ImpitBuilder`] instance.
311 fn new(config: ImpitBuilder<CookieStoreImpl>) -> Result<Self, ImpitError> {
312 let mut h3_client: Option<reqwest::Client> = None;
313 let mut base_client = Self::new_reqwest_client(&config)?;
314
315 if config.max_http_version == Version::HTTP_3 {
316 h3_client = Some(base_client);
317 base_client = Self::new_reqwest_client(&ImpitBuilder::<CookieStoreImpl> {
318 max_http_version: Version::HTTP_2,
319 ..config.clone()
320 })?;
321 }
322
323 let vanilla_client = if config.vanilla_fallback && config.fingerprint.is_some() {
324 Some(Self::new_reqwest_client(
325 &ImpitBuilder::<CookieStoreImpl> {
326 fingerprint: None,
327 max_http_version: Version::HTTP_2,
328 ..config.clone()
329 },
330 )?)
331 } else {
332 None
333 };
334
335 // Set pseudo-header order from fingerprint or fall back to browser enum
336 let pseudo_headers_order: Vec<String> = if let Some(ref fingerprint) = config.fingerprint {
337 fingerprint.http2.pseudo_header_order.to_vec()
338 } else {
339 vec![]
340 };
341
342 if !pseudo_headers_order.is_empty() {
343 std::env::set_var(
344 "IMPIT_H2_PSEUDOHEADERS_ORDER",
345 pseudo_headers_order.join(","),
346 );
347 }
348
349 Ok(Impit {
350 base_client,
351 h3_client,
352 vanilla_client,
353 config,
354 h3_engine: Arc::new(RwLock::new(None)),
355 })
356 }
357
358 fn parse_url(&self, url: String) -> Result<Url, ImpitError> {
359 let url = Url::parse(&url).map_err(|_| ImpitError::UrlParsingError(url.clone()))?;

Callers

nothing calls this directly

Calls 1

cloneMethod · 0.80

Tested by

no test coverage detected