Skip to content

Commit d0778c1

Browse files
authored
Merge pull request proxy-wasm#2 from higress-group/support-stopIteration
Support StopIteration status in onRequestHeaders and onResponseHeader…
2 parents 04dfb94 + 8b5f097 commit d0778c1

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
@@ -244,6 +244,7 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
244244

245245
WasmCallWord<2> on_request_headers_abi_01_;
246246
WasmCallWord<3> on_request_headers_abi_02_;
247+
WasmCallWord<3> on_request_headers_abi_03_;
247248
WasmCallWord<3> on_request_body_;
248249
WasmCallWord<2> on_request_trailers_;
249250
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
@@ -317,14 +317,21 @@ template <typename P> static uint32_t headerSize(const P &p) { return p ? p->siz
317317

318318
FilterHeadersStatus ContextBase::onRequestHeaders(uint32_t headers, bool end_of_stream) {
319319
CHECK_FAIL_HTTP(FilterHeadersStatus::Continue, FilterHeadersStatus::StopAllIterationAndWatermark);
320-
if (!wasm_->on_request_headers_abi_01_ && !wasm_->on_request_headers_abi_02_) {
320+
if (!wasm_->on_request_headers_abi_01_ && !wasm_->on_request_headers_abi_02_ &&
321+
!wasm_->on_request_headers_abi_03_) {
321322
return FilterHeadersStatus::Continue;
322323
}
323324
DeferAfterCallActions actions(this);
324-
const auto result = wasm_->on_request_headers_abi_01_
325-
? wasm_->on_request_headers_abi_01_(this, id_, headers)
326-
: wasm_->on_request_headers_abi_02_(this, id_, headers,
327-
static_cast<uint32_t>(end_of_stream));
325+
uint64_t result;
326+
if (wasm_->on_request_headers_abi_01_) {
327+
result = wasm_->on_request_headers_abi_01_(this, id_, headers);
328+
} else if (wasm_->on_request_headers_abi_02_) {
329+
result =
330+
wasm_->on_request_headers_abi_02_(this, id_, headers, static_cast<uint32_t>(end_of_stream));
331+
} else if (wasm_->on_request_headers_abi_03_) {
332+
result =
333+
wasm_->on_request_headers_abi_03_(this, id_, headers, static_cast<uint32_t>(end_of_stream));
334+
}
328335
CHECK_FAIL_HTTP(FilterHeadersStatus::Continue, FilterHeadersStatus::StopAllIterationAndWatermark);
329336
return convertVmCallResultToFilterHeadersStatus(result);
330337
}
@@ -493,7 +500,8 @@ FilterHeadersStatus ContextBase::convertVmCallResultToFilterHeadersStatus(uint64
493500
result > static_cast<uint64_t>(FilterHeadersStatus::StopAllIterationAndWatermark)) {
494501
return FilterHeadersStatus::StopAllIterationAndWatermark;
495502
}
496-
if (result == static_cast<uint64_t>(FilterHeadersStatus::StopIteration)) {
503+
if ((wasm_->on_request_headers_abi_01_ || wasm_->on_request_headers_abi_02_) &&
504+
result == static_cast<uint64_t>(FilterHeadersStatus::StopIteration)) {
497505
// Always convert StopIteration (pause processing headers, but continue processing body)
498506
// to StopAllIterationAndWatermark (pause all processing), since the former breaks all
499507
// assumptions about HTTP processing.

src/wasm.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ void WasmBase::getFunctions() {
200200
_GET_PROXY_ABI(on_request_headers, _abi_02);
201201
_GET_PROXY_ABI(on_response_headers, _abi_02);
202202
_GET_PROXY(on_foreign_function);
203+
} else if (abiVersion() == AbiVersion::ProxyWasm_0_2_100) {
204+
_GET_PROXY_ABI(on_request_headers, _abi_03);
203205
}
204206
#undef _GET_PROXY_ABI
205207
#undef _GET_PROXY

0 commit comments

Comments
 (0)