added option to not follow redirects

This commit is contained in:
Edward Shen 2019-05-01 17:24:18 -04:00
parent 0f4ca23655
commit e88efdae56
Signed by: edward
GPG key ID: F350507060ED6C90
2 changed files with 9 additions and 2 deletions

View file

@ -7,6 +7,7 @@ pub struct EndpointConfig {
pub port: Option<u16>, pub port: Option<u16>,
pub code: Option<u16>, pub code: Option<u16>,
pub body: Option<String>, pub body: Option<String>,
pub follow_redirects: Option<bool>,
} }
#[derive(Deserialize, Serialize, Debug, Clone)] #[derive(Deserialize, Serialize, Debug, Clone)]

View file

@ -4,7 +4,7 @@ use crate::{
State, State,
}; };
use chrono::prelude::*; use chrono::prelude::*;
use reqwest::{Client, Url, UrlError}; use reqwest::{Client, RedirectPolicy, Url, UrlError};
pub fn update_state(state: State) { pub fn update_state(state: State) {
let new_statuses = { Some(update_status(&state.read().unwrap().config)) }; let new_statuses = { Some(update_status(&state.read().unwrap().config)) };
@ -15,12 +15,18 @@ pub fn update_state(state: State) {
} }
pub fn update_status(config: &Config) -> Vec<StatusGroup> { pub fn update_status(config: &Config) -> Vec<StatusGroup> {
let client = Client::new();
let mut results: Vec<StatusGroup> = Vec::with_capacity(config.websites.len()); let mut results: Vec<StatusGroup> = Vec::with_capacity(config.websites.len());
for website_conf in &config.websites { for website_conf in &config.websites {
let mut group = Vec::with_capacity(website_conf.endpoints.len()); let mut group = Vec::with_capacity(website_conf.endpoints.len());
for endpoint in &website_conf.endpoints { for endpoint in &website_conf.endpoints {
let mut client_builder = Client::builder();
if let Some(false) = endpoint.follow_redirects {
client_builder = client_builder.redirect(RedirectPolicy::none());
}
let client = client_builder.build().unwrap();
group.push(get_result(website_conf, &client, endpoint)); group.push(get_result(website_conf, &client, endpoint));
} }