Skip to content

Commit 92963a4

Browse files
committed
address comment and improve comments
Signed-off-by: WangBaiping <[email protected]>
1 parent 1b5b700 commit 92963a4

File tree

2 files changed

+54
-42
lines changed
  • source/extensions/dynamic_modules

2 files changed

+54
-42
lines changed

source/extensions/dynamic_modules/abi.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,21 +1378,21 @@ void envoy_dynamic_module_callback_http_send_response_trailers(
13781378
// ------------------- HTTP Request/Response body callbacks --------------------
13791379

13801380
/**
1381-
* NOTE: Envoy will handle the request/response as a stream of data. Therefore, the body
1382-
* may not be available in its entirety before the end of stream flag is set. The Envoy all
1383-
* provides both the new received body and the buffered body (all historical
1384-
* data received so far) to the module. The module should be aware of this distinction
1385-
* when processing the body.
1381+
* NOTE: Envoy will handle the request/response as a stream of data. Therefore, the body may not be
1382+
* available in its entirety before the end of stream flag is set. The Envoy will provides both the
1383+
* received body (body pieces received in the latest event) and the buffered body (body pieces
1384+
* buffered so far) to the module. The module should be aware of this distinction when processing
1385+
* the body.
13861386
*
1387-
* NOTE: The new received body could only be available during the request/response body
1387+
* NOTE: The received body could only be available during the request/response body
13881388
* event hooks (the envoy_dynamic_module_on_http_filter_request_body and
13891389
* envoy_dynamic_module_on_http_filter_response_body).
1390-
* Outside of these hooks, the new received body will be unavailable.
1390+
* Outside of these hooks, the received body will be unavailable.
13911391
*
13921392
* NOTE: The buffered body, however, is always available. But only the latest data processing filter
1393-
* in the filter chain could modify the buffered body. That is say, for given filter X, the filters
1394-
* after filter X in the filter chain should have not accessed the request body yet, then filter X
1395-
* could modify the buffered body safely.
1393+
* in the filter chain could modify the buffered body. That is say for a given filter X, filter X
1394+
* can safely modify the buffered body if and only if the filters following filter X in the filter
1395+
* chain have not yet accessed the body.
13961396
*/
13971397

13981398
/**

source/extensions/dynamic_modules/sdk/rust/src/lib.rs

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,9 @@ pub trait EnvoyHttpFilter {
776776
/// Returns true if the operation is successful.
777777
fn set_filter_state_bytes(&mut self, key: &[u8], value: &[u8]) -> bool;
778778

779-
/// Get the new received request body.
780-
/// This should only be used in the `on_request_body` callback.
779+
/// Get the received request body (the request body pieces received in the latest event).
780+
/// This should only be used in the [`HttpFilter::on_request_body`] callback.
781+
///
781782
/// The body is represented as a list of [`EnvoyBuffer`].
782783
/// Memory contents pointed by each [`EnvoyBuffer`] is mutable and can be modified in place.
783784
/// However, the vector itself is a "copied view". For example, adding or removing
@@ -820,49 +821,55 @@ pub trait EnvoyHttpFilter {
820821
/// This returns None if the request body is not available.
821822
fn get_received_request_body<'a>(&'a mut self) -> Option<Vec<EnvoyMutBuffer<'a>>>;
822823

823-
/// Similar to `get_received_request_body`, but returns the historically buffered request body.
824+
/// Similar to [`get_received_request_body`], but returns the buffered request body
825+
/// (the request body pieces buffered so far in the filter chain).
824826
fn get_buffered_request_body<'a>(&'a mut self) -> Option<Vec<EnvoyMutBuffer<'a>>>;
825827

826-
/// Drain the given number of bytes from the front of the new received request body.
827-
/// This should only be used in the `on_request_body` callback.
828+
/// Drain the given number of bytes from the front of the received request body.
829+
/// This should only be used in the [`HttpFilter::on_request_body`] callback.
828830
///
829831
/// Returns false if the request body is not available.
830832
///
831833
/// Note that after changing the request body, it is caller's responsibility to modify the
832834
/// content-length header if necessary.
833835
fn drain_received_request_body(&mut self, number_of_bytes: usize) -> bool;
834836

835-
/// Similar to `drain_received_request_body`, but drains from the historically buffered request
836-
/// body. This should only be called by the latest data processing filter in the filter chain.
837-
/// That is say the filters after this filter in the filter chain should have not accessed the
838-
/// request body yet.
837+
/// Similar to [`drain_received_request_body`], but drains from the buffered request body.
838+
///
839+
/// This should only be called by the latest data processing filter in the filter chain.
840+
/// That is say for a given filter X, if and only if the filters following filter X in the filter
841+
/// chain have not yet accessed the body, filter X can safely modify the buffered body with this
842+
/// method.
839843
///
840844
/// Returns false if the request body is not available.
841845
/// Note that after changing the request body, it is caller's responsibility to modify the
842846
/// content-length header if necessary.
843847
fn drain_buffered_request_body(&mut self, number_of_bytes: usize) -> bool;
844848

845-
/// Append the given data to the end of the new received request body.
846-
/// This should only be used in the `on_request_body` callback.
849+
/// Append the given data to the end of the received request body.
850+
/// This should only be used in the [`HttpFilter::on_request_body`] callback.
847851
///
848852
/// Returns false if the request body is not available.
849853
///
850854
/// Note that after changing the request body, it is caller's responsibility to modify the
851855
/// content-length header if necessary.
852856
fn append_received_request_body(&mut self, data: &[u8]) -> bool;
853857

854-
/// Similar to `append_received_request_body`, but appends to the historically buffered request
855-
/// body. This should only be called by the latest data processing filter in the filter chain.
856-
/// That is say the filters after this filter in the filter chain should have not accessed the
857-
/// request body yet.
858+
/// Similar to [`append_received_request_body`], but appends to the buffered request body.
859+
///
860+
/// This should only be called by the latest data processing filter in the filter chain.
861+
/// That is say for a given filter X, if and only if the filters following filter X in the filter
862+
/// chain have not yet accessed the body, filter X can safely modify the buffered body with this
863+
/// method.
858864
///
859865
/// Returns false if the request body is not available.
860866
/// Note that after changing the request body, it is caller's responsibility to modify the
861867
/// content-length header if necessary.
862868
fn append_buffered_request_body(&mut self, data: &[u8]) -> bool;
863869

864-
/// Get the new received response body.
865-
/// This should only be used in the `on_response_body` callback.
870+
/// Get the received response body (the response body pieces received in the latest event).
871+
/// This should only be used in the [`HttpFilter::on_response_body`] callback.
872+
///
866873
/// The body is represented as a list of
867874
/// [`EnvoyBuffer`]. Memory contents pointed by each [`EnvoyBuffer`] is mutable and can be
868875
/// modified in place. However, the buffer itself is immutable. For example, adding or removing
@@ -888,15 +895,15 @@ pub trait EnvoyHttpFilter {
888895
/// .return_const(true);
889896
///
890897
///
891-
/// // Calculate the size of the new received response body in bytes.
898+
/// // Calculate the size of the received response body in bytes.
892899
/// let buffers = envoy_filter.get_received_response_body().unwrap();
893900
/// let mut size = 0;
894901
/// for buffer in &buffers {
895902
/// size += buffer.as_slice().len();
896903
/// }
897904
/// assert_eq!(size, 10);
898905
///
899-
/// // drain the new received response body.
906+
/// // drain the received response body.
900907
/// assert!(envoy_filter.drain_received_response_body(10));
901908
///
902909
/// // Now start writing new data from the beginning of the request body.
@@ -905,41 +912,46 @@ pub trait EnvoyHttpFilter {
905912
/// Returns None if the response body is not available.
906913
fn get_received_response_body<'a>(&'a mut self) -> Option<Vec<EnvoyMutBuffer<'a>>>;
907914

908-
/// Similar to `get_received_response_body`, but returns the historically buffered response body.
915+
/// Similar to [`get_received_response_body`], but returns the buffered response body
916+
/// (the response body pieces buffered so far in the filter chain).
909917
fn get_buffered_response_body<'a>(&'a mut self) -> Option<Vec<EnvoyMutBuffer<'a>>>;
910918

911-
/// Drain the given number of bytes from the front of the new received response body.
912-
/// This should only be used in the `on_response_body` callback.
919+
/// Drain the given number of bytes from the front of the received response body.
920+
/// This should only be used in the [`HttpFilter::on_response_body`] callback.
913921
///
914922
/// Returns false if the response body is not available.
915923
///
916924
/// Note that after changing the response body, it is caller's responsibility to modify the
917925
/// content-length header if necessary.
918926
fn drain_received_response_body(&mut self, number_of_bytes: usize) -> bool;
919927

920-
/// Similar to `drain_received_response_body`, but drains from the historically buffered response
921-
/// body. This should only be called by the latest data processing filter in the filter chain.
922-
/// That is say the filters after this filter in the filter chain should have not accessed the
923-
/// response body yet.
928+
/// Similar to [`drain_received_response_body`], but drains from the buffered response body.
929+
///
930+
/// This should only be called by the latest data processing filter in the filter chain.
931+
/// That is say for a given filter X, if and only if the filters following filter X in the filter
932+
/// chain have not yet accessed the body, filter X can safely modify the buffered body with this
933+
/// method.
924934
///
925935
/// Returns false if the response body is not available.
926936
/// Note that after changing the response body, it is caller's responsibility to modify the
927937
/// content-length header if necessary.
928938
fn drain_buffered_response_body(&mut self, number_of_bytes: usize) -> bool;
929939

930-
/// Append the given data to the end of the new received response body.
931-
/// This should only be used in the `on_response_body` callback.
940+
/// Append the given data to the end of the received response body.
941+
/// This should only be used in the [`HttpFilter::on_response_body`] callback.
932942
///
933943
/// Returns false if the response body is not available.
934944
///
935945
/// Note that after changing the response body, it is caller's responsibility to modify the
936946
/// content-length header if necessary.
937947
fn append_received_response_body(&mut self, data: &[u8]) -> bool;
938948

939-
/// Similar to `append_received_response_body`, but appends to the historically buffered response
940-
/// body. This should only be called by the latest data processing filter in the filter chain.
941-
/// That is say the filters after this filter in the filter chain should have not accessed the
942-
/// response body yet.
949+
/// Similar to [`append_received_response_body`], but appends to the buffered response body.
950+
///
951+
/// This should only be called by the latest data processing filter in the filter chain.
952+
/// That is say for a given filter X, if and only if the filters following filter X in the filter
953+
/// chain have not yet accessed the body, filter X can safely modify the buffered body with this
954+
/// method.
943955
///
944956
/// Returns false if the response body is not available.
945957
/// Note that after changing the response body, it is caller's responsibility to modify the

0 commit comments

Comments
 (0)