From d4c3b70d6290c52f903e674e9957b979abd4ce07 Mon Sep 17 00:00:00 2001 From: lamp Date: Sun, 5 Mar 2023 21:37:45 +0000 Subject: init --- src/http/rule.rs | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/http/rule.rs (limited to 'src/http/rule.rs') diff --git a/src/http/rule.rs b/src/http/rule.rs new file mode 100644 index 0000000..1672d99 --- /dev/null +++ b/src/http/rule.rs @@ -0,0 +1,123 @@ +use std::collections::HashMap; + +lazy_static! { + static ref METHODS: HashMap<&'static str, Method> = { + let mut m = HashMap::new(); + m.insert("GET", Method::GET); + m.insert("HEAD", Method::HEAD); + m.insert("POST", Method::POST); + m.insert("PUT", Method::PUT); + m.insert("DELETE", Method::DELETE); + m.insert("CONNECT", Method::CONNECT); + m.insert("OPTIONS", Method::OPTIONS); + m.insert("TRACE", Method::TRACE); + m + }; +} + +/* +* RFC 7230, Page 19 +*/ +#[derive(Debug)] +pub struct HTTPMessage { + pub request_line: RequestLine, + pub header_fields: Vec, +} + +/* +* RFC 7230, Page 23 +*/ +#[derive(Debug)] +pub struct HeaderField { + pub name: FieldName, + pub value: FieldValue, +} + +/* +* RFC 7230, Page 23 +*/ +#[derive(Debug)] +pub struct FieldName { + pub lexeme: String, +} + +/* +* RFC 7230, Page 23 +*/ +#[derive(Debug)] +pub struct FieldValue { + pub content: Vec, +} + +/* +* RFC 7230, Page 23 +*/ +#[derive(Debug)] +pub struct FieldContent { + pub first_char: u8, + pub second_char: Option, +} + +/* +* RFC 7230, Page 21 +*/ +#[derive(Debug)] +pub struct RequestLine { + pub method: Method, + pub request_target: OriginForm, + pub http_version: HTTPVersion, +} + +/* +* RFC 7231, Page 22 +*/ +#[derive(Debug, Clone)] +pub enum Method { + GET, + HEAD, + POST, + PUT, + DELETE, + CONNECT, + OPTIONS, + TRACE, +} + +impl Method { + pub fn from_string(string: &str) -> Option { + METHODS.get(string).cloned() + } +} + +/* +* RFC 7230, Page 41 +*/ +#[derive(Debug)] +pub struct OriginForm { + pub absolute_path: AbsolutePath, + pub query: Option, +} + +/* +* RFC 7230, Page 14 +*/ +#[derive(Debug)] +pub struct HTTPVersion { + pub major: u32, + pub minor: u32, +} + +#[derive(Debug)] +pub struct AbsolutePath { + pub segments: Vec, +} + +#[derive(Debug)] +pub struct Query { + pub lexeme: String, +} + +#[derive(Debug)] +pub struct Segment { + pub lexeme: String, +} -- cgit v1.2.3