aboutsummaryrefslogtreecommitdiff
path: root/src/http/rule.rs
diff options
context:
space:
mode:
authorlamp2023-03-05 21:37:45 +0000
committerlamp2023-03-05 21:37:45 +0000
commitd4c3b70d6290c52f903e674e9957b979abd4ce07 (patch)
treeba415f0f85809ffe07dd17d83ed46e5c09f2c14d /src/http/rule.rs
initmain
Diffstat (limited to 'src/http/rule.rs')
-rw-r--r--src/http/rule.rs123
1 files changed, 123 insertions, 0 deletions
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<HeaderField>,
+}
+
+/*
+* 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<u8>,
+}
+
+/*
+* RFC 7230, Page 23
+*/
+#[derive(Debug)]
+pub struct FieldContent {
+ pub first_char: u8,
+ pub second_char: Option<u8>,
+}
+
+/*
+* 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<Method> {
+ METHODS.get(string).cloned()
+ }
+}
+
+/*
+* RFC 7230, Page 41
+*/
+#[derive(Debug)]
+pub struct OriginForm {
+ pub absolute_path: AbsolutePath,
+ pub query: Option<Query>,
+}
+
+/*
+* RFC 7230, Page 14
+*/
+#[derive(Debug)]
+pub struct HTTPVersion {
+ pub major: u32,
+ pub minor: u32,
+}
+
+#[derive(Debug)]
+pub struct AbsolutePath {
+ pub segments: Vec<Segment>,
+}
+
+#[derive(Debug)]
+pub struct Query {
+ pub lexeme: String,
+}
+
+#[derive(Debug)]
+pub struct Segment {
+ pub lexeme: String,
+}