39 lines
964 B
Rust
39 lines
964 B
Rust
use core::{
|
|
future::Future,
|
|
pin::Pin,
|
|
task::{Context, Poll},
|
|
};
|
|
use std::path::PathBuf;
|
|
|
|
use hyper::{
|
|
client::{Client, HttpConnector},
|
|
http::{Request, Response},
|
|
service::Service,
|
|
Body,
|
|
};
|
|
|
|
use super::route::Route;
|
|
|
|
/// A ProxyServer is an implementation of `hyper::service::Service` that proxies requests to a
|
|
/// given list of routes.
|
|
pub struct ProxyServer
|
|
{
|
|
routes: Vec<Route>,
|
|
}
|
|
|
|
impl Service<Request<Body>> for ProxyServer
|
|
{
|
|
type Response = super::Route;
|
|
type Error = hyper::http::Error;
|
|
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
|
|
|
|
/// This function lets hyper know when the service is ready to process requests.
|
|
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
|
|
{
|
|
Poll::Ready(Ok(()))
|
|
}
|
|
|
|
/// Processes incoming requests by proxying them to other hosts.
|
|
fn call(&mut self, req: Request<Body>) -> Self::Future {}
|
|
}
|