web_transport_quinn/
server.rsuse crate::{Connect, ConnectError, Session, Settings, SettingsError};
use thiserror::Error;
use url::Url;
#[derive(Error, Debug, Clone)]
pub enum ServerError {
#[error("unexpected end of stream")]
UnexpectedEnd,
#[error("connection error")]
Connection(#[from] quinn::ConnectionError),
#[error("failed to write")]
WriteError(#[from] quinn::WriteError),
#[error("failed to read")]
ReadError(#[from] quinn::ReadError),
#[error("failed to exchange h3 settings")]
SettingsError(#[from] SettingsError),
#[error("failed to exchange h3 connect")]
ConnectError(#[from] ConnectError),
}
pub async fn accept(conn: quinn::Connection) -> Result<Request, ServerError> {
let settings = Settings::connect(&conn).await?;
let connect = Connect::accept(&conn).await?;
Ok(Request {
conn,
settings,
connect,
})
}
pub struct Request {
conn: quinn::Connection,
settings: Settings,
connect: Connect,
}
impl Request {
pub fn url(&self) -> &Url {
self.connect.url()
}
pub async fn ok(mut self) -> Result<Session, quinn::WriteError> {
self.connect.respond(http::StatusCode::OK).await?;
Ok(Session::new(self.conn, self.settings, self.connect))
}
pub async fn close(mut self, status: http::StatusCode) -> Result<(), quinn::WriteError> {
self.connect.respond(status).await?;
Ok(())
}
}