diff --git a/ubw-sward/src/http/counter.rs b/ubw-sward/src/http/counter.rs index e69de29..05e387c 100644 --- a/ubw-sward/src/http/counter.rs +++ b/ubw-sward/src/http/counter.rs @@ -0,0 +1,17 @@ +use std::sync::atomic::AtomicUsize; + +#[derive(Default)] +pub struct AtomicHttpCounter { + pub http_2xx: AtomicUsize, + pub http_3xx: AtomicUsize, + pub http_4xx: AtomicUsize, + pub http_5xx: AtomicUsize, +} + +#[derive(Default)] +pub struct HttpCounter { + pub http_2xx: usize, + pub http_3xx: usize, + pub http_4xx: usize, + pub http_5xx: usize, +} \ No newline at end of file diff --git a/ubw-sward/src/http/integrated.rs b/ubw-sward/src/http/integrated.rs index ba4ccab..5b3932b 100644 --- a/ubw-sward/src/http/integrated.rs +++ b/ubw-sward/src/http/integrated.rs @@ -11,6 +11,7 @@ use tower::ServiceExt; use tower::{BoxError, Service}; use url::Url; use wyrand::WyRand; +use crate::http::counter::{HttpCounter}; #[derive(Clone)] enum AttackTarget { @@ -21,6 +22,7 @@ enum AttackTarget { pub struct IntegratedHttpSward { attack_target: AttackTarget, request_sender: MultiplexedSward>>, + result_counter: HttpCounter } impl IntegratedHttpSward { @@ -39,6 +41,22 @@ impl IntegratedHttpSward { .await .map_err(HttpSwardError::MultiplexError)?; + match res.status().as_u16() { + 200..=299 => { + self.result_counter.http_2xx += 1; + } + 300..=399 => { + self.result_counter.http_3xx += 1; + } + 400..=499 => { + self.result_counter.http_4xx += 1; + } + 500..=599 => { + self.result_counter.http_5xx += 1; + } + _ => {} + } + Ok(res) } } @@ -154,6 +172,7 @@ impl IntegratedHttpSwardBuilder { Ok(IntegratedHttpSward { attack_target: AttackTarget::Fixed(url), request_sender: MultiplexedSward::new(SimpleHttpSward::array(swards), capacity), + result_counter: HttpCounter::default() }) } @@ -184,6 +203,7 @@ impl IntegratedHttpSwardBuilder { Ok(IntegratedHttpSward { attack_target: AttackTarget::Random(random_url_generator), request_sender: MultiplexedSward::new(SimpleHttpSward::array(swards), capacity), + result_counter: HttpCounter::default() }) } }