@@ -85,12 +85,12 @@ pub trait Context {
85
85
///
86
86
/// use log::warn;
87
87
///
88
- /// struct MyContext ;
88
+ /// struct MyPlugin ;
89
89
///
90
- /// impl HttpContext for MyContext {
90
+ /// impl HttpContext for MyPlugin {
91
91
/// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action {
92
92
/// match self.dispatch_http_call(
93
- /// "cluster_name ",
93
+ /// "cluster_name_from_envoy_config ",
94
94
/// vec![
95
95
/// (":method", "GET"),
96
96
/// (":path", "/"),
@@ -108,7 +108,7 @@ pub trait Context {
108
108
/// }
109
109
/// }
110
110
///
111
- /// impl Context for MyContext {
111
+ /// impl Context for MyPlugin {
112
112
/// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) {
113
113
/// let headers = self.get_http_call_response_headers();
114
114
/// let body = self.get_http_call_response_body(0, body_size);
@@ -151,14 +151,14 @@ pub trait Context {
151
151
/// use proxy_wasm::traits::*;
152
152
/// use proxy_wasm::types::*;
153
153
///
154
- /// use log::warn;
154
+ /// use log::{debug, warn} ;
155
155
///
156
- /// struct MyContext ;
156
+ /// struct MyPlugin ;
157
157
///
158
- /// impl HttpContext for MyContext {
158
+ /// impl HttpContext for MyPlugin {
159
159
/// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action {
160
160
/// match self.dispatch_http_call(
161
- /// "cluster_name ",
161
+ /// "google ",
162
162
/// vec![
163
163
/// (":method", "GET"),
164
164
/// (":path", "/"),
@@ -176,12 +176,12 @@ pub trait Context {
176
176
/// }
177
177
/// }
178
178
///
179
- /// impl Context for MyContext {
179
+ /// impl Context for MyPlugin {
180
180
/// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) {
181
181
/// let headers = self.get_http_call_response_headers();
182
182
/// let body = self.get_http_call_response_body(0, body_size);
183
183
///
184
- /// info !("Received response headers: {:?}", headers);
184
+ /// debug !("Received response headers: {:?}", headers);
185
185
///
186
186
/// // Do something with the response
187
187
/// }
@@ -345,29 +345,33 @@ pub trait RootContext: Context {
345
345
///
346
346
/// * `bool` - `true` if the configuration was processed successfully, `false` otherwise
347
347
///
348
- /// /// # Example
348
+ /// # Example
349
349
///
350
350
/// ```rust
351
351
/// use proxy_wasm::traits::RootContext;
352
352
///
353
353
/// struct MyRootContext;
354
354
///
355
+ /// #[derive(serde::Deserialize)]
356
+ /// #[derive(Debug)]
355
357
/// struct MyVmConfiguration {
356
358
/// /// Some key
357
359
/// pub key: String,
358
360
/// }
359
361
///
360
362
/// impl RootContext for MyRootContext {
361
363
/// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool {
362
- /// let vm_confuguration = self.get_vm_configuration().unwrap();
364
+ /// let vm_configuration = self.get_vm_configuration().unwrap();
363
365
///
364
- /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::<MyVmConfiguration>(&vm_confuguration ).unwrap();
366
+ /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::<MyVmConfiguration>(&vm_configuration ).unwrap();
365
367
///
366
368
/// // Do something with the parsed vm configuration
369
+ /// debug!("vm_configuration: {:?}", parsed_vm_configuration)
367
370
///
368
371
/// true
369
372
/// }
370
373
/// }
374
+ /// ```
371
375
fn on_vm_start ( & mut self , _vm_configuration_size : usize ) -> bool {
372
376
true
373
377
}
@@ -385,22 +389,26 @@ pub trait RootContext: Context {
385
389
///
386
390
/// struct MyRootContext;
387
391
///
392
+ /// #[derive(serde::Deserialize)]
393
+ /// #[derive(Debug)]
388
394
/// struct MyVmConfiguration {
389
395
/// /// Some key
390
396
/// pub key: String,
391
397
/// }
392
398
///
393
399
/// impl RootContext for MyRootContext {
394
400
/// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool {
395
- /// let vm_confuguration = self.get_vm_configuration().unwrap();
401
+ /// let vm_configuration = self.get_vm_configuration().unwrap();
396
402
///
397
- /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::<MyVmConfiguration>(&vm_confuguration ).unwrap();
403
+ /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::<MyVmConfiguration>(&vm_configuration ).unwrap();
398
404
///
399
405
/// // Do something with the parsed vm configuration
406
+ /// debug!("vm_configuration: {:?}", parsed_vm_configuration)
400
407
///
401
408
/// true
402
409
/// }
403
410
/// }
411
+ /// ```
404
412
fn get_vm_configuration ( & self ) -> Option < Bytes > {
405
413
hostcalls:: get_buffer ( BufferType :: VmConfiguration , 0 , usize:: MAX ) . unwrap ( )
406
414
}
@@ -423,6 +431,8 @@ pub trait RootContext: Context {
423
431
///
424
432
/// struct MyRootContext;
425
433
///
434
+ /// #[derive(serde::Deserialize)]
435
+ /// #[derive(Debug)]
426
436
/// struct MyPluginConfiguration {
427
437
/// /// Some key
428
438
/// pub key: String,
@@ -439,6 +449,7 @@ pub trait RootContext: Context {
439
449
/// true
440
450
/// }
441
451
/// }
452
+ /// ```
442
453
fn on_configure ( & mut self , _plugin_configuration_size : usize ) -> bool {
443
454
true
444
455
}
@@ -456,9 +467,11 @@ pub trait RootContext: Context {
456
467
///
457
468
/// struct MyRootContext;
458
469
///
470
+ /// #[derive(serde::Deserialize)]
471
+ /// #[derive(Debug)]
459
472
/// struct MyPluginConfiguration {
460
- /// /// Some key
461
- /// pub key: String,
473
+ /// /// Some key
474
+ /// pub key: String,
462
475
/// }
463
476
///
464
477
/// impl RootContext for MyRootContext {
@@ -472,6 +485,7 @@ pub trait RootContext: Context {
472
485
/// true
473
486
/// }
474
487
/// }
488
+ /// ```
475
489
fn get_plugin_configuration ( & self ) -> Option < Bytes > {
476
490
hostcalls:: get_buffer ( BufferType :: PluginConfiguration , 0 , usize:: MAX ) . unwrap ( )
477
491
}
@@ -503,6 +517,7 @@ pub trait RootContext: Context {
503
517
/// info!("tick!")
504
518
/// }
505
519
/// }
520
+ /// ```
506
521
fn set_tick_period ( & self , period : Duration ) {
507
522
hostcalls:: set_tick_period ( period) . unwrap ( )
508
523
}
@@ -532,6 +547,7 @@ pub trait RootContext: Context {
532
547
/// info!("tick!")
533
548
/// }
534
549
/// }
550
+ /// ```
535
551
fn on_tick ( & mut self ) { }
536
552
537
553
fn on_queue_ready ( & mut self , _queue_id : u32 ) { }
@@ -631,13 +647,16 @@ pub trait HttpContext: Context {
631
647
/// ```rust
632
648
/// use proxy_wasm::traits::*;
633
649
/// use proxy_wasm::types::*;
650
+ /// use log::debug;
634
651
///
635
- /// use log::info ;
652
+ /// struct MyPlugin ;
636
653
///
637
654
/// impl HttpContext for MyPlugin {
638
655
/// fn on_http_request_headers(&mut self, num_headers: usize, end_of_stream: bool) -> Action {
639
656
/// let headers = self.get_http_request_headers();
640
657
///
658
+ /// debug!("Received request headers: {:?}", headers);
659
+ ///
641
660
/// // Process the request
642
661
///
643
662
/// Action::Continue
@@ -657,20 +676,24 @@ pub trait HttpContext: Context {
657
676
/// # Example
658
677
///
659
678
/// ```rust
660
- /// use log::info;
661
- /// use proxy_wasm::traits::HttpContext;
679
+ /// use proxy_wasm::traits::*;
680
+ /// use proxy_wasm::types::*;
681
+ /// use log::debug;
682
+ ///
683
+ /// struct MyPlugin;
662
684
///
663
685
/// impl HttpContext for MyPlugin {
664
- /// fn on_http_request_headers(&mut self, _num_headers : usize, _end_of_stream : bool) -> Action {
686
+ /// fn on_http_request_headers(&mut self, num_headers : usize, end_of_stream : bool) -> Action {
665
687
/// let headers = self.get_http_request_headers();
666
688
///
667
- /// for (name, value) in headers {
668
- /// info!("{}: {}", name, value);
669
- /// }
689
+ /// debug!("Received request headers: {:?}", headers);
690
+ ///
691
+ /// // Process the request
692
+ ///
670
693
/// Action::Continue
671
- /// }
694
+ /// }
672
695
/// }
673
- ///
696
+ /// ```
674
697
fn get_http_request_headers ( & self ) -> Vec < ( String , String ) > {
675
698
hostcalls:: get_map ( MapType :: HttpRequestHeaders ) . unwrap ( )
676
699
}
@@ -700,21 +723,24 @@ pub trait HttpContext: Context {
700
723
/// # Example
701
724
///
702
725
/// ```rust
703
- /// use log::info ;
726
+ /// use log::debug ;
704
727
/// use proxy_wasm::traits:*;
705
728
/// use proxy_wasm::types::Action;
706
729
///
730
+ /// struct MyPlugin;
731
+ ///
707
732
/// impl HttpContext for MyPlugin {
708
733
/// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action {
709
734
/// let header = self.get_http_request_header(":path");
710
735
///
711
736
/// match header {
712
- /// Some(value) => info !("The path is: {}", value),
713
- /// None => info !("The path is missing")
737
+ /// Some(value) => debug !("The path is: {}", value),
738
+ /// None => debug !("The path is missing")
714
739
/// }
715
740
/// Action::Continue
716
741
/// }
717
742
/// }
743
+ /// ```
718
744
fn get_http_request_header ( & self , name : & str ) -> Option < String > {
719
745
hostcalls:: get_map_value ( MapType :: HttpRequestHeaders , name) . unwrap ( )
720
746
}
@@ -744,6 +770,8 @@ pub trait HttpContext: Context {
744
770
/// use proxy_wasm::traits::*;
745
771
/// use proxy_wasm::types::Action;
746
772
///
773
+ /// struct MyPlugin;
774
+ ///
747
775
/// impl HttpContext for MyPlugin {
748
776
/// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action {
749
777
/// self.add_http_request_header("x-my-header", "my-value");
@@ -950,9 +978,11 @@ pub trait HttpContext: Context {
950
978
/// use proxy_wasm::traits::*;
951
979
/// use proxy_wasm::types::*;
952
980
///
953
- /// impl HttpContext for MyHttpContext {
981
+ /// struct MyPlugin;
982
+ ///
983
+ /// impl HttpContext for MyPlugin {
954
984
/// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action {
955
- /// let auth = self.get_http_request_header("Authorization").unwrap_or_defauklt ();
985
+ /// let auth = self.get_http_request_header("Authorization").unwrap_or_default ();
956
986
///
957
987
/// if auth == "I am authorized!" {
958
988
/// // Send an HTTP response with a status code of 200 and a body of "Hello, World!"
@@ -965,6 +995,7 @@ pub trait HttpContext: Context {
965
995
/// Action::Pause
966
996
/// }
967
997
/// }
998
+ /// ```
968
999
fn send_http_response (
969
1000
& self ,
970
1001
status_code : u32 ,
0 commit comments