#![allow(dead_code)]
pub(crate) use crate::error::TransportError;
use crate::protocol::request::{BindSession, CreateSession};
pub(crate) mod framing;
pub(crate) mod http;
pub(crate) mod ws;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct TransportProperties {
pub(crate) control_shares_stream: bool,
pub(crate) ends_on_content_length: bool,
pub(crate) is_polling: bool,
}
#[derive(Debug, Clone)]
pub(crate) enum StreamOpen {
Create(Box<CreateSession>),
Bind(Box<BindSession>),
}
#[derive(Debug, Clone)]
pub(crate) struct EncodedRequest {
pub(crate) name: &'static str,
pub(crate) path: &'static str,
pub(crate) parameters: String,
}
pub(crate) trait Transport {
fn properties(&self) -> TransportProperties;
fn set_control_link(&mut self, host: Option<&str>);
fn open_stream(
&mut self,
request: StreamOpen,
) -> impl Future<Output = Result<(), TransportError>> + Send;
fn next_line(&mut self) -> impl Future<Output = Option<Result<String, TransportError>>> + Send;
fn send_control(
&mut self,
request: EncodedRequest,
) -> impl Future<Output = Result<(), TransportError>> + Send;
fn close(&mut self) -> impl Future<Output = Result<(), TransportError>> + Send;
}
#[derive(Debug)]
pub(crate) enum AnyTransport {
WebSocket(ws::WsTransport),
Http(http::HttpTransport),
}
impl Transport for AnyTransport {
fn properties(&self) -> TransportProperties {
match self {
Self::WebSocket(transport) => transport.properties(),
Self::Http(transport) => transport.properties(),
}
}
fn set_control_link(&mut self, host: Option<&str>) {
match self {
Self::WebSocket(transport) => transport.set_control_link(host),
Self::Http(transport) => transport.set_control_link(host),
}
}
async fn open_stream(&mut self, request: StreamOpen) -> Result<(), TransportError> {
match self {
Self::WebSocket(transport) => transport.open_stream(request).await,
Self::Http(transport) => transport.open_stream(request).await,
}
}
async fn next_line(&mut self) -> Option<Result<String, TransportError>> {
match self {
Self::WebSocket(transport) => transport.next_line().await,
Self::Http(transport) => transport.next_line().await,
}
}
async fn send_control(&mut self, request: EncodedRequest) -> Result<(), TransportError> {
match self {
Self::WebSocket(transport) => transport.send_control(request).await,
Self::Http(transport) => transport.send_control(request).await,
}
}
async fn close(&mut self) -> Result<(), TransportError> {
match self {
Self::WebSocket(transport) => transport.close().await,
Self::Http(transport) => transport.close().await,
}
}
}