add http response counter to integrated http sward
This commit is contained in:
@@ -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,
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ use tower::ServiceExt;
|
|||||||
use tower::{BoxError, Service};
|
use tower::{BoxError, Service};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use wyrand::WyRand;
|
use wyrand::WyRand;
|
||||||
|
use crate::http::counter::{HttpCounter};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
enum AttackTarget {
|
enum AttackTarget {
|
||||||
@@ -21,6 +22,7 @@ enum AttackTarget {
|
|||||||
pub struct IntegratedHttpSward {
|
pub struct IntegratedHttpSward {
|
||||||
attack_target: AttackTarget,
|
attack_target: AttackTarget,
|
||||||
request_sender: MultiplexedSward<HttpSwardArray<Box<[SimpleHttpSward]>>>,
|
request_sender: MultiplexedSward<HttpSwardArray<Box<[SimpleHttpSward]>>>,
|
||||||
|
result_counter: HttpCounter
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntegratedHttpSward {
|
impl IntegratedHttpSward {
|
||||||
@@ -39,6 +41,22 @@ impl IntegratedHttpSward {
|
|||||||
.await
|
.await
|
||||||
.map_err(HttpSwardError::MultiplexError)?;
|
.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)
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,6 +172,7 @@ impl IntegratedHttpSwardBuilder {
|
|||||||
Ok(IntegratedHttpSward {
|
Ok(IntegratedHttpSward {
|
||||||
attack_target: AttackTarget::Fixed(url),
|
attack_target: AttackTarget::Fixed(url),
|
||||||
request_sender: MultiplexedSward::new(SimpleHttpSward::array(swards), capacity),
|
request_sender: MultiplexedSward::new(SimpleHttpSward::array(swards), capacity),
|
||||||
|
result_counter: HttpCounter::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,6 +203,7 @@ impl IntegratedHttpSwardBuilder {
|
|||||||
Ok(IntegratedHttpSward {
|
Ok(IntegratedHttpSward {
|
||||||
attack_target: AttackTarget::Random(random_url_generator),
|
attack_target: AttackTarget::Random(random_url_generator),
|
||||||
request_sender: MultiplexedSward::new(SimpleHttpSward::array(swards), capacity),
|
request_sender: MultiplexedSward::new(SimpleHttpSward::array(swards), capacity),
|
||||||
|
result_counter: HttpCounter::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user