1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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,
}
|