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
124
125
use http::{request::Parts, HeaderMap, Method, Uri, Version};
use crate::Server;
#[derive(Debug)]
pub struct Request(pub(crate) Parts, pub(crate) Vec<u8>, pub(crate) Server);
impl Request {
pub fn new(req: http::Request<Vec<u8>>, server: Server) -> Self {
let (parts, body) = req.into_parts();
Self(parts, body, server)
}
pub fn uri(&self) -> &Uri {
&self.0.uri
}
pub fn version(&self) -> Version {
self.0.version
}
pub fn method(&self) -> &Method {
&self.0.method
}
pub fn headers(&self) -> &HeaderMap {
&self.0.headers
}
pub fn headers_mut(&mut self) -> &mut HeaderMap {
&mut self.0.headers
}
pub fn body(&self) -> &Vec<u8> {
&self.1
}
#[cfg(feature = "cookies")]
pub fn cookies(&self) -> cookie::CookieJar {
use {
cookie::{Cookie, CookieJar},
http::header::COOKIE,
};
let mut jar = CookieJar::new();
for cookie in self
.0
.headers
.get_all(COOKIE)
.into_iter()
.filter_map(|value| value.to_str().ok())
.flat_map(|value| value.split(';'))
.filter_map(|cookie| Cookie::parse_encoded(cookie.to_owned()).ok())
{
jar.add_original(cookie);
}
jar
}
pub fn query_pairs(&self) -> Option<form_urlencoded::Parse<'_>> {
self.0
.uri
.query()
.map(|query| form_urlencoded::parse(query.as_bytes()))
}
pub fn into_parts(self) -> (Parts, Vec<u8>) {
(self.0, self.1)
}
pub fn parts(&self) -> &Parts {
&self.0
}
pub fn parts_mut(&mut self) -> &mut Parts {
&mut self.0
}
pub fn expose(self) -> http::Request<Vec<u8>> {
http::Request::from_parts(self.0, self.1)
}
pub fn extensions(&self) -> &http::Extensions {
&self.0.extensions
}
pub fn extensions_mut(&mut self) -> &mut http::Extensions {
&mut self.0.extensions
}
pub fn server(&self) -> Server {
self.2
}
#[doc(hidden)]
pub fn _internal_dangerously_clone(&self) -> Self {
let mut parts = http::Request::<()>::default().into_parts().0;
parts.method = self.0.method.clone();
parts.uri = self.0.uri.clone();
parts.version = self.0.version;
parts.headers = self.0.headers.clone();
Self(parts, self.1.clone(), self.2)
}
}