Skip to content

Commit

Permalink
gui/common: Use curl user agent to make Yle happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Nykseli committed Oct 15, 2023
1 parent 7982838 commit 6417716
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/gui/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,20 @@ impl<T: HtmlParser + TelePager + Send + 'static> GuiContext<T> {

#[cfg(not(target_arch = "wasm32"))]
fn fetch_page(site: &str) -> Result<T, ()> {
let body = reqwest::blocking::get(site).map_err(|_| ())?;
let body = body.text().map_err(|_| ())?;
let teletext = T::new()
.parse(HtmlLoader { page_data: body })
.map_err(|_| ())?;
use reqwest::header::{HeaderMap, HeaderValue};

// let body = reqwest::blocking::get(site).unwrap();
let mut headers = HeaderMap::new();
headers.insert("user-agent", HeaderValue::from_static("curl/7.81.0"));
let body = reqwest::blocking::Client::builder()
.default_headers(headers)
.build()
.unwrap()
.get(site)
.send()
.unwrap();
let body = body.text().unwrap();
let teletext = T::new().parse(HtmlLoader { page_data: body }).unwrap();
Ok(teletext)
}

Expand Down

0 comments on commit 6417716

Please sign in to comment.