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
extern crate std;
use std::prelude::v1::*;
use proxy_wasm::types::Bytes;
use crate::extension::Result;
use crate::host;
use crate::host::services::clients::http as http_client;
pub mod context;
pub mod ops;
pub use context::LoggerContext;
pub trait Logger {
fn on_configure(
&mut self,
_configuration_size: usize,
_logger_ops: &dyn ConfigureOps,
) -> Result<bool> {
Ok(true)
}
fn on_log(&mut self, _logger_ops: &dyn LogOps) -> Result<()> {
Ok(())
}
fn on_http_call_response(
&mut self,
_request: http_client::RequestHandle,
_num_headers: usize,
_body_size: usize,
_num_trailers: usize,
_http_client_ops: &dyn http_client::ResponseOps,
) -> Result<()> {
Ok(())
}
}
pub trait ConfigureOps {
fn get_configuration(&self) -> host::Result<Option<Bytes>>;
}
pub trait LogOps {
fn get_request_headers(&self) -> host::Result<Vec<(String, String)>>;
fn get_request_header(&self, name: &str) -> host::Result<Option<String>>;
fn get_response_headers(&self) -> host::Result<Vec<(String, String)>>;
fn get_response_header(&self, name: &str) -> host::Result<Option<String>>;
fn get_response_trailers(&self) -> host::Result<Vec<(String, String)>>;
fn get_response_trailer(&self, name: &str) -> host::Result<Option<String>>;
fn get_property(&self, path: Vec<&str>) -> host::Result<Option<Bytes>>;
}
pub trait Ops: ConfigureOps + LogOps {
fn as_configure_ops(&self) -> &dyn ConfigureOps;
fn as_log_ops(&self) -> &dyn LogOps;
}
impl<T> Ops for T
where
T: ConfigureOps + LogOps,
{
fn as_configure_ops(&self) -> &dyn ConfigureOps {
self
}
fn as_log_ops(&self) -> &dyn LogOps {
self
}
}