@@ -72,18 +72,15 @@ pub trait Context {
72
72
///
73
73
/// # Returns
74
74
///
75
- /// * `OK` on success.
76
- /// * `BAD_ARGUMENT` for unknown upstream, or when headers are missing required `:authority`, `:method` and/or `:path` values.
77
- /// * `INTERNAL_FAILURE' when the host failed to send requested HTTP call.
78
- /// * `INVALID_MEMORY_ACCESS` when `upstream_data`, `upstream_size`, `headers_data`, `headers_size`, `body_data`, `body_size`, `trailers_data`, `trailers_size` and/or `return_call_id` point to invalid memory address.
75
+ /// A Result containing the token id of the request, or an error status.
79
76
///
80
77
/// # Example
81
78
///
82
79
/// ```rust
83
80
/// use proxy_wasm::traits::*;
84
81
/// use proxy_wasm::types::*;
85
82
/// use std::time::Duration;
86
- /// use log::warn;
83
+ /// use log::{debug, warn} ;
87
84
///
88
85
/// struct MyPlugin;
89
86
///
@@ -113,7 +110,7 @@ pub trait Context {
113
110
/// let headers = self.get_http_call_response_headers();
114
111
/// let body = self.get_http_call_response_body(0, body_size);
115
112
///
116
- /// info !("Received response headers: {:?}", headers);
113
+ /// debug !("Received response headers: {:?}", headers);
117
114
///
118
115
/// // Do something with the response
119
116
/// }
@@ -130,13 +127,13 @@ pub trait Context {
130
127
hostcalls:: dispatch_http_call ( upstream, headers, body, trailers, timeout)
131
128
}
132
129
133
- /// Called when HTTP response for call_id sent using proxy_http_call is received.
130
+ /// Called when HTTP response using `dispatch_http_call` is received.
134
131
///
135
132
/// If `num_headers` is 0, then the HTTP call failed.
136
133
///
137
- /// All `num_headers` headers can be retrieved using `self.get_http_response_headers()` or individually `self.get_http_response_header()`.
134
+ /// All headers can be retrieved using `self.get_http_response_headers()` or individually `self.get_http_response_header(name )`.
138
135
///
139
- /// All `num_trailers` trailers can be retrieved using `self.get_http_response_trailers()` or individually `self.get_http_response_trailer()`.
136
+ /// All trailers can be retrieved using `self.get_http_response_trailers()` or individually `self.get_http_response_trailer(name )`.
140
137
///
141
138
/// # Arguments
142
139
///
@@ -350,7 +347,6 @@ pub trait RootContext: Context {
350
347
/// ```rust
351
348
/// use proxy_wasm::traits::*;
352
349
/// use proxy_wasm::types::*;
353
- /// use serde_json;
354
350
/// use log::debug;
355
351
///
356
352
/// struct MyRootContext;
@@ -365,7 +361,8 @@ pub trait RootContext: Context {
365
361
/// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool {
366
362
/// let vm_configuration = self.get_vm_configuration().unwrap();
367
363
///
368
- /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::<MyVmConfiguration>(&vm_configuration).unwrap();
364
+ /// let parsed_vm_configuration: MyVmConfiguration =
365
+ /// serde_json::from_slice::<MyVmConfiguration>(&vm_configuration).unwrap();
369
366
///
370
367
/// // Do something with the parsed vm configuration
371
368
/// debug!("vm_configuration: {:?}", parsed_vm_configuration)
@@ -389,7 +386,6 @@ pub trait RootContext: Context {
389
386
/// ```rust
390
387
/// use proxy_wasm::traits::*;
391
388
/// use proxy_wasm::types::*;
392
- /// use serde_json;
393
389
/// use log::debug;
394
390
///
395
391
/// struct MyRootContext;
@@ -404,7 +400,8 @@ pub trait RootContext: Context {
404
400
/// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool {
405
401
/// let vm_configuration = self.get_vm_configuration().unwrap();
406
402
///
407
- /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::<MyVmConfiguration>(&vm_configuration).unwrap();
403
+ /// let parsed_vm_configuration: MyVmConfiguration =
404
+ /// serde_json::from_slice::<MyVmConfiguration>(&vm_configuration).unwrap();
408
405
///
409
406
/// // Do something with the parsed vm configuration
410
407
/// debug!("vm_configuration: {:?}", parsed_vm_configuration)
@@ -433,7 +430,6 @@ pub trait RootContext: Context {
433
430
/// ```rust
434
431
/// use proxy_wasm::traits::*;
435
432
/// use proxy_wasm::types::*;
436
- /// use serde_json;
437
433
/// use log::debug;
438
434
///
439
435
/// struct MyRootContext;
@@ -448,7 +444,8 @@ pub trait RootContext: Context {
448
444
/// fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool {
449
445
/// let plugin_configuration = self.get_plugin_configuration().unwrap();
450
446
///
451
- /// let parsed_plugin_configuration: MyPluginConfiguration = serde_json::from_slice::<MyPluginConfiguration>(&plugin_configuration).unwrap();
447
+ /// let parsed_plugin_configuration: MyPluginConfiguration =
448
+ /// serde_json::from_slice::<MyPluginConfiguration>(&plugin_configuration).unwrap();
452
449
///
453
450
/// // Do something with the parsed plugin configuration
454
451
/// debug!("plugin_configuration: {:?}", parsed_plugin_configuration)
@@ -472,7 +469,6 @@ pub trait RootContext: Context {
472
469
/// ```rust
473
470
/// use proxy_wasm::traits::*;
474
471
/// use proxy_wasm::types::*;
475
- /// use serde_json;
476
472
/// use log::debug;
477
473
///
478
474
/// struct MyRootContext;
@@ -487,7 +483,8 @@ pub trait RootContext: Context {
487
483
/// fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool {
488
484
/// let plugin_configuration = self.get_plugin_configuration().unwrap();
489
485
///
490
- /// let parsed_plugin_configuration: MyPluginConfiguration = serde_json::from_slice::<MyPluginConfiguration>(&plugin_configuration).unwrap();
486
+ /// let parsed_plugin_configuration: MyPluginConfiguration =
487
+ /// serde_json::from_slice::<MyPluginConfiguration>(&plugin_configuration).unwrap();
491
488
///
492
489
/// // Do something with the parsed plugin configuration
493
490
/// debug!("plugin_configuration: {:?}", parsed_plugin_configuration)
@@ -640,7 +637,7 @@ pub trait HttpContext: Context {
640
637
///
641
638
/// Paused request can be resumed using `self.resume_http_request()` or closed using `self.reset_http_request()`.
642
639
///
643
- /// Additionally, instead of forwarding request upstream, a HTTP response can be sent using `self.send_http_response()`.
640
+ /// Additionally, instead of forwarding requests upstream, a HTTP response can be sent using `self.send_http_response()`.
644
641
///
645
642
/// # Arguments
646
643
///
@@ -722,7 +719,7 @@ pub trait HttpContext: Context {
722
719
hostcalls:: set_map_bytes ( MapType :: HttpRequestHeaders , headers) . unwrap ( )
723
720
}
724
721
725
- /// Get a specific HTTP request header.
722
+ /// Get a specific HTTP request header by name .
726
723
///
727
724
/// # Arguments
728
725
///
@@ -973,9 +970,9 @@ pub trait HttpContext: Context {
973
970
hostcalls:: reset_http_response ( ) . unwrap ( )
974
971
}
975
972
976
- /// Sends an HTTP response with the body and serialized headers.
973
+ /// Sends an HTTP response with the specified status code, headers, and body .
977
974
///
978
- /// This can be used as long as HTTP response headers were not sent downstream.
975
+ /// This can be used as long as HTTP response headers were not sent downstream yet .
979
976
///
980
977
/// # Arguments
981
978
///
@@ -1000,7 +997,7 @@ pub trait HttpContext: Context {
1000
997
/// // Send an HTTP response with a status code of 200 and a body of "Hello, World!"
1001
998
/// self.send_http_response(200, vec![("A header", "Some Value")], Some(b"Hello, World!"));
1002
999
/// } else {
1003
- /// // Send an HTTP response with a status code of 403 and a body of "Forbidden"
1000
+ /// // Send an HTTP response with a status code of 307, redirecting to authenticate-here.com, and a body of "Forbidden"
1004
1001
/// self.send_http_response(307, vec![("location", "https://authenticate-here.com")], Some(b"Forbidden"));
1005
1002
/// }
1006
1003
///
0 commit comments