MCPcopy Create free account
hub / github.com/emwalker/digraph / fetch

Method fetch

backend/src/http/page.rs:34–59  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

32 }
33
34 pub fn fetch(&self) -> Result<Response> {
35 if !self.should_fetch() {
36 log::info!(
37 "document not suitable for fetching, skipping fetch: {}",
38 self.0
39 );
40 return Ok(Response {
41 url: self.0.clone(),
42 body: Html::parse_document("<title>Missing title [pdf]</title>"),
43 });
44 }
45
46 log::info!("fetching page: {}", self.0);
47 let text = ureq::get(&self.0.normalized)
48 .timeout(Duration::from_secs(20_000))
49 .set("User-Agent", USER_AGENT)
50 .call()?
51 .into_string()?;
52 let body = Html::parse_fragment(text.as_ref());
53
54 log::info!("page fetched: {}", self.0);
55 Ok(Response {
56 url: self.0.clone(),
57 body,
58 })
59 }
60
61 pub fn should_fetch(&self) -> bool {
62 !self.0.is_pdf() && !self.0.avoid_requests()

Callers 4

visit_parent_topicMethod · 0.45
visit_topic_childMethod · 0.45
mainFunction · 0.45

Calls 2

should_fetchMethod · 0.80
callMethod · 0.45

Tested by

no test coverage detected