spacegate_kernel/
extractor.rs1use hyper::Request;
2
3use crate::SgBody;
4use hyper::http;
5pub trait Extract: Sized + Send + Sync {
7 fn extract(req: &Request<SgBody>) -> Self;
8}
9
10impl Extract for http::uri::Uri {
11 fn extract(req: &Request<SgBody>) -> Self {
12 req.uri().clone()
13 }
14}
15
16impl Extract for http::method::Method {
17 fn extract(req: &Request<SgBody>) -> Self {
18 req.method().clone()
19 }
20}
21
22impl Extract for http::Version {
23 fn extract(req: &Request<SgBody>) -> Self {
24 req.version()
25 }
26}
27
28pub trait OptionalExtract: Sized + Send + Sync {
29 fn extract(req: &Request<SgBody>) -> Option<Self>;
30}
31
32impl<T> Extract for Option<T>
33where
34 T: OptionalExtract,
35{
36 fn extract(req: &Request<SgBody>) -> Option<T> {
37 <T as OptionalExtract>::extract(req)
38 }
39}
40
41#[cfg(feature = "ext-redis")]
42impl OptionalExtract for spacegate_ext_redis::RedisClient {
43 fn extract(req: &Request<SgBody>) -> Option<Self> {
44 crate::SgRequestExt::get_redis_client_by_gateway_name(req)
45 }
46}