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
pub use hyper::Method;
pub use hyper::Uri;
pub use hyper::HttpVersion;
pub use hyper::Headers;
pub use hyper::Response;
pub use hyper::Body;
pub use hyper::StatusCode;
pub use hyper::server::Http;
pub use hyper::server::Service;
pub use hyper::Request;
use futures::Future;
use futures::Stream;
#[derive(Debug)]
pub struct SyncRequest {
method: Method,
uri: Uri,
version: HttpVersion,
headers: Headers,
body: Vec<u8>,
}
impl SyncRequest {
#[inline]
pub fn new(method: Method,
uri: Uri,
version: HttpVersion,
headers: Headers,
body: Vec<u8>
) -> SyncRequest {
SyncRequest {
method,
uri,
version,
headers,
body,
}
}
#[inline]
pub fn uri(&self) -> &Uri { &self.uri }
#[inline]
pub fn version(&self) -> HttpVersion { self.version }
#[inline]
pub fn headers(&self) -> &Headers { &self.headers }
#[inline]
pub fn method(&self) -> &Method { &self.method }
#[inline]
pub fn body_ref(&self) -> &Vec<u8> { self.body.as_ref() }
#[inline]
pub fn body_mut(&mut self) -> &mut Vec<u8> { &mut self.body }
#[inline]
pub fn path(&self) -> &str {
self.uri.path()
}
#[inline]
pub fn query(&self) -> Option<&str> {
self.uri.query()
}
#[inline]
pub fn headers_mut(&mut self) -> &mut Headers { &mut self.headers }
}
pub trait LoadBody {
fn load_body(self) -> Box<Future<Item=SyncRequest, Error=::hyper::Error>>;
}
impl LoadBody for Request<Body> {
fn load_body(self) -> Box<Future<Item=SyncRequest, Error=::hyper::Error>> {
let (method, uri, version, headers, body) = self.deconstruct();
Box::new(body.concat2().map( move |b| {
let body_vec: Vec<u8> = b.to_vec();
SyncRequest::new(method, uri, version, headers, body_vec)
}))
}
}