feat: boxygit add .

This commit is contained in:
hexlocation 2025-07-29 11:47:02 +02:00
parent ba8d1b9453
commit a8bc61f40c
15 changed files with 4700 additions and 0 deletions

View file

@ -0,0 +1,60 @@
use std::{pin::Pin, sync::Arc};
use http_body_util::Full;
use hyper::{
Request, Response,
body::{Bytes, Incoming},
service::Service,
};
use log::error;
use tokio::sync::Mutex;
use crate::{
config::{self, Client, Config, Host},
db::{BoxyDatabase, Endpoint},
types::{GeneralBody, GeneralResponse, TcpIntercept},
};
use super::proxy::ProxyService;
#[derive(Debug, Clone)]
pub struct ControllerService {
pub database: Arc<Mutex<&'static mut BoxyDatabase>>,
}
impl TcpIntercept for ControllerService {
fn handle(&mut self, stream: &tokio::net::TcpStream) {
}
}
impl Service<Request<Incoming>> for ControllerService {
type Response = GeneralResponse;
type Error = hyper::Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn call(&self, req: Request<Incoming>) -> Self::Future {
let database = self.database.clone();
Box::pin(async move {
let hostname = req
.headers()
.get(hyper::header::HOST)
.unwrap()
.to_str()
.unwrap()
.to_string();
let endpoints = Endpoint::get_by_hostname(*database.lock().await, hostname.clone())
.await
.unwrap();
let endpoint = endpoints.first().unwrap();
let proxy = ProxyService {
address: format!("{}:{}", endpoint.address.clone(), endpoint.port),
hostname,
};
proxy.call(req).await
})
}
}