(&self)
| 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() |
no test coverage detected