Compare commits
2 Commits
e4ab06de26
...
74b728c10d
| Author | SHA1 | Date | |
|---|---|---|---|
| 74b728c10d | |||
| 344e383a18 |
@@ -1,12 +1,14 @@
|
||||
use crate::http::header_config::HeadersConfig;
|
||||
use crate::http::simple::HttpSwardArray;
|
||||
use crate::http::{RandomUrlGenerator, SimpleHttpSward};
|
||||
use crate::utils::multiplexed::MultiplexedSward;
|
||||
use crate::http::{RandomUrlGenerator, SimpleHttpRequest, SimpleHttpSward};
|
||||
use crate::utils::multiplexed::{MultiplexedSward, MultiplexedSwardError};
|
||||
use rand::Rng;
|
||||
use reqwest::Method;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::sync::Arc;
|
||||
use thiserror::Error;
|
||||
use tower::ServiceExt;
|
||||
use tower::{BoxError, Service};
|
||||
use url::Url;
|
||||
use wyrand::WyRand;
|
||||
|
||||
@@ -21,6 +23,26 @@ pub struct IntegratedHttpSward {
|
||||
request_sender: MultiplexedSward<HttpSwardArray<Box<[SimpleHttpSward]>>>,
|
||||
}
|
||||
|
||||
impl IntegratedHttpSward {
|
||||
pub async fn oneshot(&mut self) -> Result<reqwest::Response, HttpSwardError> {
|
||||
let url = match &mut self.attack_target {
|
||||
AttackTarget::Random(random) => random.generate_url()?,
|
||||
AttackTarget::Fixed(url) => url.clone(),
|
||||
};
|
||||
let request = SimpleHttpRequest { body: None, url };
|
||||
let res = self
|
||||
.request_sender
|
||||
.ready()
|
||||
.await
|
||||
.map_err(HttpSwardError::MultiplexError)?
|
||||
.call(request)
|
||||
.await
|
||||
.map_err(HttpSwardError::MultiplexError)?;
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntegratedHttpSward {
|
||||
pub fn builder() -> IntegratedHttpSwardBuilder {
|
||||
IntegratedHttpSwardBuilder::new()
|
||||
@@ -180,3 +202,12 @@ pub enum HttpSwardBuildError {
|
||||
#[error("Failed to build reqwest client {0}")]
|
||||
ReqwestBuildError(#[from] reqwest::Error),
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum HttpSwardError {
|
||||
#[error("Error when pooling")]
|
||||
MultiplexError(MultiplexedSwardError<BoxError>),
|
||||
|
||||
#[error(transparent)]
|
||||
BadUrl(#[from] url::ParseError),
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use bytes::Bytes;
|
||||
use reqwest::header::HeaderMap;
|
||||
use reqwest::{Client, Method};
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use tower::Service;
|
||||
@@ -52,7 +53,7 @@ pub struct SimpleHttpRequest {
|
||||
impl Service<SimpleHttpRequest> for SimpleHttpSward {
|
||||
type Response = reqwest::Response;
|
||||
type Error = reqwest::Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ where
|
||||
/// Error that can occur when multiplexing requests.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum MultiplexedSwardError<E> {
|
||||
#[error("{0}")]
|
||||
#[error(transparent)]
|
||||
Inner(E),
|
||||
|
||||
#[error("Semaphore is closed.")]
|
||||
|
||||
Reference in New Issue
Block a user