/
request_proxy.rs
63 lines (59 loc) · 1.63 KB
/
request_proxy.rs
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
extern crate old_semver;
use std::io::Read;
use std::net::SocketAddr;
use self::old_semver::semver;
use conduit;
use conduit::Request;
// Can't derive Debug because of Request.
#[allow(missing_debug_implementations)]
pub struct RequestProxy<'a> {
pub other: &'a mut (dyn Request + 'a),
pub path: Option<&'a str>,
pub method: Option<conduit::Method>,
}
impl<'a> Request for RequestProxy<'a> {
fn http_version(&self) -> semver::Version {
self.other.http_version()
}
fn conduit_version(&self) -> semver::Version {
self.other.conduit_version()
}
fn method(&self) -> conduit::Method {
self.method
.clone()
.unwrap_or_else(|| self.other.method().clone())
}
fn scheme(&self) -> conduit::Scheme {
self.other.scheme()
}
fn host(&self) -> conduit::Host<'_> {
self.other.host()
}
fn virtual_root(&self) -> Option<&str> {
self.other.virtual_root()
}
fn path(&self) -> &str {
self.path.unwrap_or_else(|| self.other.path())
}
fn query_string(&self) -> Option<&str> {
self.other.query_string()
}
fn remote_addr(&self) -> SocketAddr {
self.other.remote_addr()
}
fn content_length(&self) -> Option<u64> {
self.other.content_length()
}
fn headers(&self) -> &dyn conduit::Headers {
self.other.headers()
}
fn body(&mut self) -> &mut dyn Read {
self.other.body()
}
fn extensions(&self) -> &conduit::Extensions {
self.other.extensions()
}
fn mut_extensions(&mut self) -> &mut conduit::Extensions {
self.other.mut_extensions()
}
}