12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- use std:: str;
16
15
use proxy_wasm:: traits:: * ;
17
16
use proxy_wasm:: types:: * ;
17
+ use std:: str;
18
18
19
19
#[ no_mangle]
20
20
pub fn _start ( ) {
21
21
proxy_wasm:: set_log_level ( LogLevel :: Trace ) ;
22
22
proxy_wasm:: set_root_context ( |_| -> Box < dyn RootContext > {
23
- Box :: new ( HttpConfigHeaderRootContext {
23
+ Box :: new ( HttpConfigHeaderRootContext {
24
24
header_content : "" . to_string ( ) ,
25
25
} )
26
26
} ) ;
27
27
}
28
28
29
- struct HttpConfigHeader {
30
- header_content : String
29
+ struct HttpConfigHeader {
30
+ header_content : String ,
31
31
}
32
32
33
33
impl Context for HttpConfigHeader { }
34
34
35
35
impl HttpContext for HttpConfigHeader {
36
-
37
36
fn on_http_response_headers ( & mut self , _num_headers : usize ) -> Action {
38
37
self . add_http_response_header ( "custom-header" , self . header_content . as_str ( ) ) ;
39
38
@@ -42,13 +41,12 @@ impl HttpContext for HttpConfigHeader {
42
41
}
43
42
44
43
struct HttpConfigHeaderRootContext {
45
- header_content : String
44
+ header_content : String ,
46
45
}
47
46
48
47
impl Context for HttpConfigHeaderRootContext { }
49
48
50
49
impl RootContext for HttpConfigHeaderRootContext {
51
-
52
50
fn on_configure ( & mut self , _plugin_configuration_size : usize ) -> bool {
53
51
if let Some ( config_bytes) = self . get_configuration ( ) {
54
52
self . header_content = str:: from_utf8 ( config_bytes. as_ref ( ) ) . unwrap ( ) . to_owned ( )
@@ -57,13 +55,12 @@ impl RootContext for HttpConfigHeaderRootContext {
57
55
}
58
56
59
57
fn create_http_context ( & self , _context_id : u32 ) -> Option < Box < dyn HttpContext > > {
60
- Some ( Box :: new ( HttpConfigHeader {
58
+ Some ( Box :: new ( HttpConfigHeader {
61
59
header_content : self . header_content . clone ( ) ,
62
60
} ) )
63
61
}
64
62
65
63
fn get_type ( & self ) -> Option < ContextType > {
66
64
Some ( ContextType :: HttpContext )
67
65
}
68
-
69
66
}
0 commit comments