use serde::{Serialize, Deserialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum EnvRequest {
Http(EnvRequestHttp),
Ws(EnvRequestWs),
Cli(EnvRequestCli),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnvRequestInfo {
pub r#type: String,
pub host: String,
pub ip: Option<String>,
pub method: Option<String>,
pub path: Option<String>,
pub headers: Option<HashMap<String, String>>,
pub args: Option<Vec<String>>,
}
impl From<&EnvRequest> for EnvRequestInfo {
fn from(req: &EnvRequest) -> Self {
match req {
EnvRequest::Http(http) => EnvRequestInfo {
r#type: "http".into(),
host: http.host.clone(),
ip: http.ip.clone(),
method: Some(http.method.clone()),
path: Some(http.path.clone()),
headers: Some(http.headers.clone()),
args: None,
},
EnvRequest::Ws(ws) => EnvRequestInfo {
r#type: "ws".into(),
host: ws.host.clone(),
ip: ws.ip.clone(),
method: None,
path: None,
headers: Some(ws.headers.clone()),
args: None,
},
EnvRequest::Cli(cli) => EnvRequestInfo {
r#type: "cli".into(),
host: "localhost".into(),
ip: None,
method: Some(cli.command.clone()),
path: Some(cli.args.join(" ")),
headers: None,
args: Some(cli.args.clone()),
},
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnvRequestHttp {
pub host: String,
pub ip: Option<String>,
pub method: String,
pub path: String,
pub headers: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnvRequestWs {
pub host: String,
pub ip: Option<String>,
pub headers: HashMap<String, String>,
pub payload: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct EnvRequestCli {
pub command: String,
pub args: Vec<String>,
pub env: HashMap<String, String>,
}