save
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
use crate::http::header_config::HeadersConfig;
|
use crate::http::header_config::HeadersConfig;
|
||||||
use crate::http::simple::HttpSwardArray;
|
use crate::http::simple::HttpSwardArray;
|
||||||
use crate::http::{RandomUrlGenerator, SimpleHttpSward};
|
use crate::http::{RandomUrlGenerator, SimpleHttpRequest, SimpleHttpSward};
|
||||||
use crate::utils::multiplexed::MultiplexedSward;
|
use crate::utils::multiplexed::{MultiplexedSward, MultiplexedSwardError};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
use std::net::{IpAddr, SocketAddr};
|
use std::net::{IpAddr, SocketAddr};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use tower::ServiceExt;
|
||||||
|
use tower::Service;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use wyrand::WyRand;
|
use wyrand::WyRand;
|
||||||
|
|
||||||
@@ -21,6 +23,22 @@ pub struct IntegratedHttpSward {
|
|||||||
request_sender: MultiplexedSward<HttpSwardArray<Box<[SimpleHttpSward]>>>,
|
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()?.call(request);
|
||||||
|
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl IntegratedHttpSward {
|
impl IntegratedHttpSward {
|
||||||
pub fn builder() -> IntegratedHttpSwardBuilder {
|
pub fn builder() -> IntegratedHttpSwardBuilder {
|
||||||
IntegratedHttpSwardBuilder::new()
|
IntegratedHttpSwardBuilder::new()
|
||||||
@@ -180,3 +198,15 @@ pub enum HttpSwardBuildError {
|
|||||||
#[error("Failed to build reqwest client {0}")]
|
#[error("Failed to build reqwest client {0}")]
|
||||||
ReqwestBuildError(#[from] reqwest::Error),
|
ReqwestBuildError(#[from] reqwest::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum HttpSwardError {
|
||||||
|
#[error("Http Response: {0}")]
|
||||||
|
HttpCode(u8),
|
||||||
|
|
||||||
|
#[error(transparent)]
|
||||||
|
MultiplexError(#[from] MultiplexedSwardError<reqwest::Error>),
|
||||||
|
|
||||||
|
#[error(transparent)]
|
||||||
|
BadUrl(#[from] url::ParseError)
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ use reqwest::header::HeaderMap;
|
|||||||
use reqwest::{Client, Method};
|
use reqwest::{Client, Method};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tower::Service;
|
use tower::{Service, ServiceExt};
|
||||||
use tower::balance::p2c::Balance;
|
use tower::balance::p2c::Balance;
|
||||||
use tower::discover::ServiceList;
|
use tower::discover::ServiceList;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ where
|
|||||||
/// Error that can occur when multiplexing requests.
|
/// Error that can occur when multiplexing requests.
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum MultiplexedSwardError<E> {
|
pub enum MultiplexedSwardError<E> {
|
||||||
#[error("{0}")]
|
#[error(transparent)]
|
||||||
Inner(E),
|
Inner(E),
|
||||||
|
|
||||||
#[error("Semaphore is closed.")]
|
#[error("Semaphore is closed.")]
|
||||||
|
|||||||
Reference in New Issue
Block a user