Abort early if the URL is invalid

This commit is contained in:
Yash Karandikar 2022-07-29 15:48:12 -05:00 committed by lemonsh
parent 154572f6be
commit d8b477d2b4

View file

@ -3,6 +3,7 @@ use async_trait::async_trait;
use fancy_regex::{Captures, Regex};
use htmlescape::decode_html;
use hyper::header::HeaderValue;
use hyper::Uri;
use reqwest::Client;
pub struct Title {
@ -29,6 +30,10 @@ impl Trigger for Title {
let url = captures.get(0).unwrap().as_str();
tracing::debug!("url: {}", url);
if url.parse::<Uri>().is_err() {
return Ok("\x039[Title]\x0311 Invalid URL".into());
}
let request = self.http.get(url).build()?;
let response = self.http.execute(request).await?;
let headers = response.headers();