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
use hyper::{Headers, Method, Uri};
use hyper::header::{self, Header};
use hyper::mime::Mime;
use hyper::error::UriError;
#[derive(Debug)]
pub struct Request {
pub(crate) method: Method,
pub(crate) uri: Uri,
pub(crate) headers: Headers,
}
impl Request {
pub fn new(method: Method, uri: &str) -> Result<Request, UriError> {
Ok(Request {
method,
uri: uri.parse()?,
headers: Default::default(),
})
}
pub fn method(&self) -> &Method {
&self.method
}
pub fn path(&self) -> &str {
self.uri.path()
}
pub fn query(&self) -> Option<&str> {
self.uri.query()
}
pub fn header<H: Header>(&self) -> Option<&H> {
self.headers.get::<H>()
}
#[allow(missing_docs)]
pub fn media_type(&self) -> Option<&Mime> {
self.header().map(|&header::ContentType(ref m)| m)
}
}