Skip to main content

prosa_hyper/client/
adaptor.rs

1use std::convert::Infallible;
2
3use bytes::Bytes;
4use http_body_util::combinators::BoxBody;
5use hyper::{Request, Response};
6use prosa::core::{error::ProcError, service::ServiceError};
7use url::Url;
8
9use crate::client::proc::HyperClientProc;
10
11#[cfg_attr(doc, aquamarine::aquamarine)]
12/// Trait to define the Hyper adaptor structure
13///
14/// ```mermaid
15/// graph LR
16///     OUT1[Output HTTP server]
17///     ProSA[ProSA Hyper Procesor]
18///
19///     ProSA-- HTTP request (process_client_request) -->OUT
20///     OUT-- HTTP response (process_client_response) -->ProSA
21/// ```
22pub trait HyperClientAdaptor<M>
23where
24    M: 'static
25        + std::marker::Send
26        + std::marker::Sync
27        + std::marker::Sized
28        + std::clone::Clone
29        + std::fmt::Debug
30        + prosa::core::msg::Tvf
31        + std::default::Default,
32{
33    /// Create a new adaptor
34    fn new(proc: &HyperClientProc<M>) -> Result<Self, Box<dyn ProcError + Send + Sync>>
35    where
36        Self: Sized;
37
38    /// Method to process input HTTP requests. Received by the ProSA through Hyper
39    fn process_srv_request(
40        &self,
41        request: M,
42        socket_url: &Url,
43    ) -> Result<Request<BoxBody<Bytes, Infallible>>, ServiceError>;
44
45    /// Method to process input HTTP response to respond with an TVF response.
46    fn process_http_response(
47        &self,
48        resp: Result<Response<hyper::body::Incoming>, hyper::Error>,
49    ) -> impl std::future::Future<Output = Result<M, ServiceError>> + Send;
50}