Skip to content

Commit 38c94a1

Browse files
committed
Support StopIteration status in onRequestHeaders and onResponseHeaders function
Link: https://code.alibaba-inc.com/Ingress/proxy-wasm-cpp-host/codereview/14120411 * Support StopIteration status in onRequestHeaders and onResponseHeaders function Signed-off-by: leilei.gll <[email protected]> * Remove the on_response_headers_abi_03 interface Signed-off-by: leilei.gll <[email protected]> * Remove on_response_headers_abi_03 Signed-off-by: leilei.gll <[email protected]>
1 parent 624ef2e commit 38c94a1

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

include/proxy-wasm/wasm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
245245

246246
WasmCallWord<2> on_request_headers_abi_01_;
247247
WasmCallWord<3> on_request_headers_abi_02_;
248+
WasmCallWord<3> on_request_headers_abi_03_;
248249
WasmCallWord<3> on_request_body_;
249250
WasmCallWord<2> on_request_trailers_;
250251
WasmCallWord<2> on_request_metadata_;

include/proxy-wasm/wasm_vm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ enum class Cloneable {
139139
InstantiatedModule // VMs can be cloned from an instantiated module.
140140
};
141141

142-
enum class AbiVersion { ProxyWasm_0_1_0, ProxyWasm_0_2_0, ProxyWasm_0_2_1, Unknown };
142+
enum class AbiVersion { ProxyWasm_0_1_0, ProxyWasm_0_2_0, ProxyWasm_0_2_1, ProxyWasm_0_2_100, Unknown };
143143

144144
class NullPlugin;
145145

src/bytecode_util.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ bool BytecodeUtil::getAbiVersion(std::string_view bytecode, proxy_wasm::AbiVersi
8383
ret = AbiVersion::ProxyWasm_0_2_1;
8484
return true;
8585
}
86+
if (export_name == "proxy_abi_version_0_2_100") {
87+
ret = AbiVersion::ProxyWasm_0_2_100;
88+
return true;
89+
}
8690
}
8791
// Skip export's index.
8892
if (!parseVarint(pos, end, export_name_size)) {

src/context.cc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,21 @@ template <typename P> static uint32_t headerSize(const P &p) { return p ? p->siz
311311

312312
FilterHeadersStatus ContextBase::onRequestHeaders(uint32_t headers, bool end_of_stream) {
313313
CHECK_FAIL_HTTP(FilterHeadersStatus::Continue, FilterHeadersStatus::StopAllIterationAndWatermark);
314-
if (!wasm_->on_request_headers_abi_01_ && !wasm_->on_request_headers_abi_02_) {
314+
if (!wasm_->on_request_headers_abi_01_ && !wasm_->on_request_headers_abi_02_ &&
315+
!wasm_->on_request_headers_abi_03_) {
315316
return FilterHeadersStatus::Continue;
316317
}
317318
DeferAfterCallActions actions(this);
318-
const auto result = wasm_->on_request_headers_abi_01_
319-
? wasm_->on_request_headers_abi_01_(this, id_, headers)
320-
: wasm_->on_request_headers_abi_02_(this, id_, headers,
321-
static_cast<uint32_t>(end_of_stream));
319+
uint64_t result;
320+
if (wasm_->on_request_headers_abi_01_) {
321+
result = wasm_->on_request_headers_abi_01_(this, id_, headers);
322+
} else if (wasm_->on_request_headers_abi_02_) {
323+
result =
324+
wasm_->on_request_headers_abi_02_(this, id_, headers, static_cast<uint32_t>(end_of_stream));
325+
} else if (wasm_->on_request_headers_abi_03_) {
326+
result =
327+
wasm_->on_request_headers_abi_03_(this, id_, headers, static_cast<uint32_t>(end_of_stream));
328+
}
322329
CHECK_FAIL_HTTP(FilterHeadersStatus::Continue, FilterHeadersStatus::StopAllIterationAndWatermark);
323330
return convertVmCallResultToFilterHeadersStatus(result);
324331
}
@@ -487,7 +494,8 @@ FilterHeadersStatus ContextBase::convertVmCallResultToFilterHeadersStatus(uint64
487494
result > static_cast<uint64_t>(FilterHeadersStatus::StopAllIterationAndWatermark)) {
488495
return FilterHeadersStatus::StopAllIterationAndWatermark;
489496
}
490-
if (result == static_cast<uint64_t>(FilterHeadersStatus::StopIteration)) {
497+
if ((wasm_->on_request_headers_abi_01_ || wasm_->on_request_headers_abi_02_) &&
498+
result == static_cast<uint64_t>(FilterHeadersStatus::StopIteration)) {
491499
// Always convert StopIteration (pause processing headers, but continue processing body)
492500
// to StopAllIterationAndWatermark (pause all processing), since the former breaks all
493501
// assumptions about HTTP processing.

src/wasm.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ void WasmBase::getFunctions() {
179179
_GET_PROXY_ABI(on_request_headers, _abi_02);
180180
_GET_PROXY_ABI(on_response_headers, _abi_02);
181181
_GET_PROXY(on_foreign_function);
182+
} else if (abiVersion() == AbiVersion::ProxyWasm_0_2_100) {
183+
_GET_PROXY_ABI(on_request_headers, _abi_03);
182184
}
183185
#undef _GET_PROXY_ABI
184186
#undef _GET_PROXY

0 commit comments

Comments
 (0)