#![forbid(unsafe_code)]
use bytes::Bytes;
use http::{HeaderMap, Method, StatusCode, Uri, Version};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ProxiedRequest {
#[serde(with = "http_serde::method")]
method: Method,
#[serde(with = "http_serde::uri")]
uri: Uri,
#[serde(with = "http_serde::version")]
version: Version,
#[serde(with = "http_serde::header_map")]
headers: HeaderMap,
body: Bytes,
time: i64,
}
impl ProxiedRequest {
pub const fn new(
method: Method,
uri: Uri,
version: Version,
headers: HeaderMap,
body: Bytes,
time: i64,
) -> Self {
Self {
method,
uri,
version,
headers,
body,
time,
}
}
pub const fn method(&self) -> &Method {
&self.method
}
pub const fn uri(&self) -> &Uri {
&self.uri
}
pub const fn version(&self) -> Version {
self.version
}
pub const fn headers(&self) -> &HeaderMap {
&self.headers
}
pub const fn body(&self) -> &Bytes {
&self.body
}
pub const fn time(&self) -> i64 {
self.time
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum WsDirection {
ClientToServer,
ServerToClient,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum WsOpcode {
Continuation,
Text,
Binary,
Close,
Ping,
Pong,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WsFrame {
pub direction: WsDirection,
pub opcode: WsOpcode,
pub time: i64,
pub payload: Bytes,
pub truncated: bool,
}
impl WsFrame {
pub fn new(
direction: WsDirection,
opcode: WsOpcode,
time: i64,
payload: Bytes,
truncated: bool,
) -> Self {
Self {
direction,
opcode,
time,
payload,
truncated,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ProxiedResponse {
#[serde(with = "http_serde::status_code")]
status: StatusCode,
#[serde(with = "http_serde::version")]
version: Version,
#[serde(with = "http_serde::header_map")]
headers: HeaderMap,
body: Bytes,
time: i64,
}
impl ProxiedResponse {
pub const fn new(
status: StatusCode,
version: Version,
headers: HeaderMap,
body: Bytes,
time: i64,
) -> Self {
Self {
status,
version,
headers,
body,
time,
}
}
pub const fn status(&self) -> StatusCode {
self.status
}
pub const fn version(&self) -> Version {
self.version
}
pub const fn headers(&self) -> &HeaderMap {
&self.headers
}
pub const fn body(&self) -> &Bytes {
&self.body
}
pub const fn time(&self) -> i64 {
self.time
}
}