Skip to content

Commit 2cd1cbf

Browse files
committed
dynamic modules: new body processing ABI (envoyproxy#41790)
Signed-off-by: WangBaiping <[email protected]>
1 parent 1c9a0bf commit 2cd1cbf

File tree

8 files changed

+1020
-284
lines changed

8 files changed

+1020
-284
lines changed

changelogs/current.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ date: Pending
22

33
behavior_changes:
44
# *Changes that are expected to cause an incompatibility if applicable; deployment changes are likely required*
5+
- area: dynamic modules
6+
change: |
7+
The dynamic module ABI has been updated to support streaming body manipulation. This change also
8+
fixed potential incorrect behavior when access or modify the request or response body. See
9+
https://github.com/envoyproxy/envoy/issues/40918 for more details.
510
611
minor_behavior_changes:
712
# *Changes that may cause incompatibilities for some users, but should not for most*

source/extensions/dynamic_modules/abi.h

Lines changed: 147 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -959,14 +959,32 @@ void envoy_dynamic_module_callback_http_send_response(
959959
// ------------------- HTTP Request/Response body callbacks --------------------
960960

961961
/**
962-
* envoy_dynamic_module_callback_http_get_request_body_vector is called by the module to get the
963-
* request body as a vector of buffers. The body is returned as an array of
962+
* NOTE: Envoy will handle the request/response as a stream of data. Therefore, the body may not be
963+
* available in its entirety before the end of stream flag is set. The Envoy will provides both the
964+
* received body (body pieces received in the latest event) and the buffered body (body pieces
965+
* buffered so far) to the module. The module should be aware of this distinction when processing
966+
* the body.
967+
*
968+
* NOTE: The received body could only be available during the request/response body
969+
* event hooks (the envoy_dynamic_module_on_http_filter_request_body and
970+
* envoy_dynamic_module_on_http_filter_response_body).
971+
* Outside of these hooks, the received body will be unavailable.
972+
*
973+
* NOTE: The buffered body, however, is always available. But only the latest data processing filter
974+
* in the filter chain could modify the buffered body. That is say for a given filter X, filter X
975+
* can safely modify the buffered body if and only if the filters following filter X in the filter
976+
* chain have not yet accessed the body.
977+
*/
978+
979+
/**
980+
* envoy_dynamic_module_callback_http_get_received_request_body_vector is called by the module to
981+
* get the current request body as a vector of buffers. The body is returned as an array of
964982
* envoy_dynamic_module_type_envoy_buffer.
965983
*
966984
* PRECONDITION: The module must ensure that the result_buffer_vector is valid and has enough length
967985
* to store all the buffers. The module can use
968-
* envoy_dynamic_module_callback_http_get_request_body_vector_size to get the number of buffers
969-
* before calling this function.
986+
* envoy_dynamic_module_callback_http_get_received_request_body_vector_size to get the number of
987+
* buffers before calling this function.
970988
*
971989
* @param filter_envoy_ptr is the pointer to the DynamicModuleHttpFilter object of the
972990
* corresponding HTTP filter.
@@ -975,82 +993,179 @@ void envoy_dynamic_module_callback_http_send_response(
975993
* end of the current event hook unless the setter callback is called.
976994
* @return true if the body is available, false otherwise.
977995
*/
978-
bool envoy_dynamic_module_callback_http_get_request_body_vector(
996+
bool envoy_dynamic_module_callback_http_get_received_request_body_vector(
979997
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr,
980998
envoy_dynamic_module_type_envoy_buffer* result_buffer_vector);
981999

9821000
/**
983-
* envoy_dynamic_module_callback_http_get_request_body_vector_size is called by the module to get
984-
* the number of buffers in the request body. Combined with
985-
* envoy_dynamic_module_callback_http_get_request_body_vector, this can be used to iterate over all
986-
* buffers in the request body.
1001+
* envoy_dynamic_module_callback_http_get_buffered_request_body_vector is called by the module to
1002+
* get the buffered request body as a vector of buffers. The body is returned as an array of
1003+
* envoy_dynamic_module_type_envoy_buffer.
1004+
*
1005+
* PRECONDITION: The module must ensure that the result_buffer_vector is valid and has enough length
1006+
* to store all the buffers. The module can use
1007+
* envoy_dynamic_module_callback_http_get_buffered_request_body_vector_size to get the number of
1008+
* buffers before calling this function.
1009+
*
1010+
* @param filter_envoy_ptr is the pointer to the DynamicModuleHttpFilter object of the
1011+
* corresponding HTTP filter.
1012+
* @param result_buffer_vector is the pointer to the array of envoy_dynamic_module_type_envoy_buffer
1013+
* where the buffers of the body will be stored. The lifetime of the buffer is guaranteed until the
1014+
* end of the current event hook unless the setter callback is called.
1015+
* @return true if the body is available, false otherwise.
1016+
*/
1017+
bool envoy_dynamic_module_callback_http_get_buffered_request_body_vector(
1018+
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr,
1019+
envoy_dynamic_module_type_envoy_buffer* result_buffer_vector);
1020+
1021+
/**
1022+
* envoy_dynamic_module_callback_http_get_received_request_body_vector_size is called by the module
1023+
* to get the number of buffers in the current request body. Combined with
1024+
* envoy_dynamic_module_callback_http_get_received_request_body_vector, this can be used to iterate
1025+
* over all buffers in the request body.
9871026
*
9881027
* @param filter_envoy_ptr is the pointer to the DynamicModuleHttpFilter object of the
9891028
* corresponding HTTP filter.
9901029
* @param size is the pointer to the variable where the number of buffers will be stored.
9911030
* @return true if the body is available, false otherwise.
9921031
*/
993-
bool envoy_dynamic_module_callback_http_get_request_body_vector_size(
1032+
bool envoy_dynamic_module_callback_http_get_received_request_body_vector_size(
9941033
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr, size_t* size);
9951034

9961035
/**
997-
* envoy_dynamic_module_callback_http_append_request_body is called by the module to append the
998-
* given data to the end of the request body.
1036+
* envoy_dynamic_module_callback_http_get_buffered_request_body_vector_size is called by the module
1037+
* to get the number of buffers in the buffered request body. Combined with
1038+
* envoy_dynamic_module_callback_http_get_buffered_request_body_vector, this can be used to iterate
1039+
* over all buffers in the request body.
1040+
*
1041+
* @param filter_envoy_ptr is the pointer to the DynamicModuleHttpFilter object of the
1042+
* corresponding HTTP filter.
1043+
* @param size is the pointer to the variable where the number of buffers will be stored.
1044+
* @return true if the body is available, false otherwise.
1045+
*/
1046+
bool envoy_dynamic_module_callback_http_get_buffered_request_body_vector_size(
1047+
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr, size_t* size);
1048+
1049+
/**
1050+
* envoy_dynamic_module_callback_http_append_received_request_body is called by the module to append
1051+
* the given data to the end of the current request body.
9991052
*
10001053
* @param filter_envoy_ptr is the pointer to the DynamicModuleHttpFilter object of the
10011054
* corresponding HTTP filter.
10021055
* @param data is the pointer to the buffer of the data to be appended.
10031056
* @param length is the length of the data.
10041057
* @return true if the body is available, false otherwise.
10051058
*/
1006-
bool envoy_dynamic_module_callback_http_append_request_body(
1059+
bool envoy_dynamic_module_callback_http_append_received_request_body(
10071060
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr,
10081061
envoy_dynamic_module_type_buffer_module_ptr data, size_t length);
10091062

10101063
/**
1011-
* envoy_dynamic_module_callback_http_drain_request_body is called by the module to drain the given
1012-
* number of bytes from the request body. If the number of bytes to drain is greater than
1013-
* the size of the body, the whole body will be drained.
1064+
* envoy_dynamic_module_callback_http_append_buffered_request_body is called by the module to append
1065+
* the given data to the end of the buffered request body.
1066+
*
1067+
* @param filter_envoy_ptr is the pointer to the DynamicModuleHttpFilter object of the
1068+
* corresponding HTTP filter.
1069+
* @param data is the pointer to the buffer of the data to be appended.
1070+
* @param length is the length of the data.
1071+
* @return true if the body is available, false otherwise.
1072+
*/
1073+
bool envoy_dynamic_module_callback_http_append_buffered_request_body(
1074+
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr,
1075+
envoy_dynamic_module_type_buffer_module_ptr data, size_t length);
1076+
1077+
/**
1078+
* envoy_dynamic_module_callback_http_drain_received_request_body is called by the module to drain
1079+
* the given number of bytes from the current request body. If the number of bytes to drain is
1080+
* greater than the size of the body, the whole body will be drained.
10141081
*
10151082
* @param filter_envoy_ptr is the pointer to the DynamicModuleHttpFilter object of the
10161083
* corresponding HTTP filter.
10171084
* @param number_of_bytes is the number of bytes to drain.
10181085
* @return true if the body is available, false otherwise.
10191086
*/
1020-
bool envoy_dynamic_module_callback_http_drain_request_body(
1087+
bool envoy_dynamic_module_callback_http_drain_received_request_body(
10211088
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr, size_t number_of_bytes);
10221089

10231090
/**
1024-
* This is the same as envoy_dynamic_module_callback_http_get_request_body_vector, but for the
1025-
* response body. See the comments on envoy_dynamic_module_callback_http_get_request_body_vector
1026-
* for more details.
1091+
* envoy_dynamic_module_callback_http_drain_buffered_request_body is called by the module to drain
1092+
* the given number of bytes from the buffered request body. If the number of bytes to drain is
1093+
* greater than the size of the body, the whole body will be drained.
1094+
*
1095+
* @param filter_envoy_ptr is the pointer to the DynamicModuleHttpFilter object of the
1096+
* corresponding HTTP filter.
1097+
* @param number_of_bytes is the number of bytes to drain.
1098+
* @return true if the body is available, false otherwise.
1099+
*/
1100+
bool envoy_dynamic_module_callback_http_drain_buffered_request_body(
1101+
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr, size_t number_of_bytes);
1102+
1103+
/**
1104+
* This is the same as envoy_dynamic_module_callback_http_get_received_request_body_vector, but for
1105+
* the current response body. See the comments on
1106+
* envoy_dynamic_module_callback_http_get_received_request_body_vector for more details.
1107+
*/
1108+
bool envoy_dynamic_module_callback_http_get_received_response_body_vector(
1109+
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr,
1110+
envoy_dynamic_module_type_envoy_buffer* result_buffer_vector);
1111+
1112+
/**
1113+
* This is the same as envoy_dynamic_module_callback_http_get_buffered_request_body_vector, but for
1114+
* the buffered response body. See the comments on
1115+
* envoy_dynamic_module_callback_http_get_buffered_request_body_vector for more details.
10271116
*/
1028-
bool envoy_dynamic_module_callback_http_get_response_body_vector(
1117+
bool envoy_dynamic_module_callback_http_get_buffered_response_body_vector(
10291118
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr,
10301119
envoy_dynamic_module_type_envoy_buffer* result_buffer_vector);
10311120

10321121
/**
1033-
* This is the same as envoy_dynamic_module_callback_http_get_request_body_vector_size, but for the
1034-
* response body. See the comments on
1035-
* envoy_dynamic_module_callback_http_get_request_body_vector_size for more details.
1122+
* This is the same as envoy_dynamic_module_callback_http_get_received_request_body_vector_size, but
1123+
* for the current response body. See the comments on
1124+
* envoy_dynamic_module_callback_http_get_received_request_body_vector_size for more details.
10361125
*/
1037-
bool envoy_dynamic_module_callback_http_get_response_body_vector_size(
1126+
bool envoy_dynamic_module_callback_http_get_received_response_body_vector_size(
10381127
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr, size_t* size);
10391128

10401129
/**
1041-
* This is the same as envoy_dynamic_module_callback_http_append_request_body, but for the response
1042-
* body. See the comments on envoy_dynamic_module_callback_http_append_request_body for more
1043-
* details.
1130+
* This is the same as envoy_dynamic_module_callback_http_get_buffered_request_body_vector_size, but
1131+
* for the buffered response body. See the comments on
1132+
* envoy_dynamic_module_callback_http_get_buffered_request_body_vector_size for more details.
10441133
*/
1045-
bool envoy_dynamic_module_callback_http_append_response_body(
1134+
bool envoy_dynamic_module_callback_http_get_buffered_response_body_vector_size(
1135+
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr, size_t* size);
1136+
1137+
/**
1138+
* This is the same as envoy_dynamic_module_callback_http_append_received_request_body, but for the
1139+
* current response body. See the comments on
1140+
* envoy_dynamic_module_callback_http_append_received_request_body for more details.
1141+
*/
1142+
bool envoy_dynamic_module_callback_http_append_received_response_body(
10461143
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr,
10471144
envoy_dynamic_module_type_buffer_module_ptr data, size_t length);
10481145

10491146
/**
1050-
* This is the same as envoy_dynamic_module_callback_http_drain_request_body, but for the response
1051-
* body. See the comments on envoy_dynamic_module_callback_http_drain_request_body for more details.
1147+
* This is the same as envoy_dynamic_module_callback_http_append_buffered_request_body, but for the
1148+
* buffered response body. See the comments on
1149+
* envoy_dynamic_module_callback_http_append_buffered_request_body for more details.
1150+
*/
1151+
bool envoy_dynamic_module_callback_http_append_buffered_response_body(
1152+
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr,
1153+
envoy_dynamic_module_type_buffer_module_ptr data, size_t length);
1154+
1155+
/**
1156+
* This is the same as envoy_dynamic_module_callback_http_drain_received_request_body, but for the
1157+
* current response body. See the comments on
1158+
* envoy_dynamic_module_callback_http_drain_received_request_body for more details.
1159+
*/
1160+
bool envoy_dynamic_module_callback_http_drain_received_response_body(
1161+
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr, size_t number_of_bytes);
1162+
1163+
/**
1164+
* This is the same as envoy_dynamic_module_callback_http_drain_buffered_request_body, but for the
1165+
* buffered response body. See the comments on
1166+
* envoy_dynamic_module_callback_http_drain_buffered_request_body for more details.
10521167
*/
1053-
bool envoy_dynamic_module_callback_http_drain_response_body(
1168+
bool envoy_dynamic_module_callback_http_drain_buffered_response_body(
10541169
envoy_dynamic_module_type_http_filter_envoy_ptr filter_envoy_ptr, size_t number_of_bytes);
10551170

10561171
// ---------------------------- Metadata Callbacks -----------------------------

0 commit comments

Comments
 (0)