framework-web 26.8.150

lingting framework
Documentation
use bytes::Bytes;
use framework_core::MultiStringValue;
use std::fmt::{Display, Formatter};

#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum WebMethod {
    Get,
    Post,
    Put,
    Patch,
    Delete,
    Options,
    Other(String),
}

impl WebMethod {
    pub fn from_name(value: &str) -> Self {
        let value = value.to_ascii_uppercase();
        match value.as_str() {
            "GET" => Self::Get,
            "POST" => Self::Post,
            "PUT" => Self::Put,
            "PATCH" => Self::Patch,
            "DELETE" => Self::Delete,
            "OPTIONS" => Self::Options,
            _ => Self::Other(value),
        }
    }
}

impl Display for WebMethod {
    fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Get => formatter.write_str("GET"),
            Self::Post => formatter.write_str("POST"),
            Self::Put => formatter.write_str("PUT"),
            Self::Patch => formatter.write_str("PATCH"),
            Self::Delete => formatter.write_str("DELETE"),
            Self::Options => formatter.write_str("OPTIONS"),
            Self::Other(value) => formatter.write_str(value),
        }
    }
}

#[derive(Debug)]
pub struct WebRequest {
    pub method: WebMethod,
    pub scheme: String,
    pub authority: String,
    pub path: String,
    pub headers: MultiStringValue,
    pub query: MultiStringValue,
    pub body: Bytes,
    pub client_ip: Option<String>,
    /// 链路标识:优先取 `x-trace-id` 请求头,缺失时由服务器生成。
    pub trace_id: String,
    /// 服务器收到请求的时刻(毫秒时间戳)。
    pub receive_time: i64,
}