added option to not follow redirects

master
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 code: Option<u16>,
pub body: Option<String>,
pub follow_redirects: Option<bool>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]

View File

@ -4,7 +4,7 @@ use crate::{
State,
};
use chrono::prelude::*;
use reqwest::{Client, Url, UrlError};
use reqwest::{Client, RedirectPolicy, Url, UrlError};
pub fn update_state(state: State) {
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> {
let client = Client::new();
let mut results: Vec<StatusGroup> = Vec::with_capacity(config.websites.len());
for website_conf in &config.websites {
let mut group = Vec::with_capacity(website_conf.endpoints.len());
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));
}