implement oneshot

This commit is contained in:
2025-09-04 01:42:38 +09:00
parent 344e383a18
commit 74b728c10d
2 changed files with 19 additions and 17 deletions

View File

@@ -8,7 +8,7 @@ use std::net::{IpAddr, SocketAddr};
use std::sync::Arc; use std::sync::Arc;
use thiserror::Error; use thiserror::Error;
use tower::ServiceExt; use tower::ServiceExt;
use tower::Service; use tower::{BoxError, Service};
use url::Url; use url::Url;
use wyrand::WyRand; use wyrand::WyRand;
@@ -27,15 +27,19 @@ impl IntegratedHttpSward {
pub async fn oneshot(&mut self) -> Result<reqwest::Response, HttpSwardError> { pub async fn oneshot(&mut self) -> Result<reqwest::Response, HttpSwardError> {
let url = match &mut self.attack_target { let url = match &mut self.attack_target {
AttackTarget::Random(random) => random.generate_url()?, AttackTarget::Random(random) => random.generate_url()?,
AttackTarget::Fixed(url) => url.clone() AttackTarget::Fixed(url) => url.clone(),
}; };
let request = SimpleHttpRequest { let request = SimpleHttpRequest { body: None, url };
body: None, let res = self
url .request_sender
}; .ready()
let res = self.request_sender.ready()?.call(request); .await
.map_err(HttpSwardError::MultiplexError)?
.call(request)
.await
.map_err(HttpSwardError::MultiplexError)?;
todo!() Ok(res)
} }
} }
@@ -201,12 +205,9 @@ pub enum HttpSwardBuildError {
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum HttpSwardError { pub enum HttpSwardError {
#[error("Http Response: {0}")] #[error("Error when pooling")]
HttpCode(u8), MultiplexError(MultiplexedSwardError<BoxError>),
#[error(transparent)] #[error(transparent)]
MultiplexError(#[from] MultiplexedSwardError<reqwest::Error>), BadUrl(#[from] url::ParseError),
}
#[error(transparent)]
BadUrl(#[from] url::ParseError)
}

View File

@@ -1,9 +1,10 @@
use bytes::Bytes; use bytes::Bytes;
use reqwest::header::HeaderMap; use reqwest::header::HeaderMap;
use reqwest::{Client, Method}; use reqwest::{Client, Method};
use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use tower::{Service, ServiceExt}; use tower::Service;
use tower::balance::p2c::Balance; use tower::balance::p2c::Balance;
use tower::discover::ServiceList; use tower::discover::ServiceList;
use url::Url; use url::Url;
@@ -52,7 +53,7 @@ pub struct SimpleHttpRequest {
impl Service<SimpleHttpRequest> for SimpleHttpSward { impl Service<SimpleHttpRequest> for SimpleHttpSward {
type Response = reqwest::Response; type Response = reqwest::Response;
type Error = reqwest::Error; 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>> { fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(())) Poll::Ready(Ok(()))
} }