Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support StopIteration status in onRequestHeaders and onResponseHeader… #397

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/proxy-wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {

WasmCallWord<2> on_request_headers_abi_01_;
WasmCallWord<3> on_request_headers_abi_02_;
WasmCallWord<3> on_request_headers_abi_03_;
WasmCallWord<3> on_request_body_;
WasmCallWord<2> on_request_trailers_;
WasmCallWord<2> on_request_metadata_;
Expand Down
2 changes: 1 addition & 1 deletion include/proxy-wasm/wasm_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ enum class Cloneable {
InstantiatedModule // VMs can be cloned from an instantiated module.
};

enum class AbiVersion { ProxyWasm_0_1_0, ProxyWasm_0_2_0, ProxyWasm_0_2_1, Unknown };
enum class AbiVersion { ProxyWasm_0_1_0, ProxyWasm_0_2_0, ProxyWasm_0_2_1, ProxyWasm_0_2_100, Unknown };

class NullPlugin;

Expand Down
4 changes: 4 additions & 0 deletions src/bytecode_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ bool BytecodeUtil::getAbiVersion(std::string_view bytecode, proxy_wasm::AbiVersi
ret = AbiVersion::ProxyWasm_0_2_1;
return true;
}
if (export_name == "proxy_abi_version_0_2_100") {
ret = AbiVersion::ProxyWasm_0_2_100;
return true;
}
}
// Skip export's index.
if (!parseVarint(pos, end, export_name_size)) {
Expand Down
20 changes: 14 additions & 6 deletions src/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,21 @@ template <typename P> static uint32_t headerSize(const P &p) { return p ? p->siz

FilterHeadersStatus ContextBase::onRequestHeaders(uint32_t headers, bool end_of_stream) {
CHECK_FAIL_HTTP(FilterHeadersStatus::Continue, FilterHeadersStatus::StopAllIterationAndWatermark);
if (!wasm_->on_request_headers_abi_01_ && !wasm_->on_request_headers_abi_02_) {
if (!wasm_->on_request_headers_abi_01_ && !wasm_->on_request_headers_abi_02_ &&
!wasm_->on_request_headers_abi_03_) {
return FilterHeadersStatus::Continue;
}
DeferAfterCallActions actions(this);
const auto result = wasm_->on_request_headers_abi_01_
? wasm_->on_request_headers_abi_01_(this, id_, headers)
: wasm_->on_request_headers_abi_02_(this, id_, headers,
static_cast<uint32_t>(end_of_stream));
uint64_t result;
if (wasm_->on_request_headers_abi_01_) {
result = wasm_->on_request_headers_abi_01_(this, id_, headers);
} else if (wasm_->on_request_headers_abi_02_) {
result =
wasm_->on_request_headers_abi_02_(this, id_, headers, static_cast<uint32_t>(end_of_stream));
} else if (wasm_->on_request_headers_abi_03_) {
result =
wasm_->on_request_headers_abi_03_(this, id_, headers, static_cast<uint32_t>(end_of_stream));
}
CHECK_FAIL_HTTP(FilterHeadersStatus::Continue, FilterHeadersStatus::StopAllIterationAndWatermark);
return convertVmCallResultToFilterHeadersStatus(result);
}
Expand Down Expand Up @@ -493,7 +500,8 @@ FilterHeadersStatus ContextBase::convertVmCallResultToFilterHeadersStatus(uint64
result > static_cast<uint64_t>(FilterHeadersStatus::StopAllIterationAndWatermark)) {
return FilterHeadersStatus::StopAllIterationAndWatermark;
}
if (result == static_cast<uint64_t>(FilterHeadersStatus::StopIteration)) {
if ((wasm_->on_request_headers_abi_01_ || wasm_->on_request_headers_abi_02_) &&
result == static_cast<uint64_t>(FilterHeadersStatus::StopIteration)) {
// Always convert StopIteration (pause processing headers, but continue processing body)
// to StopAllIterationAndWatermark (pause all processing), since the former breaks all
// assumptions about HTTP processing.
Expand Down
2 changes: 2 additions & 0 deletions src/wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ void WasmBase::getFunctions() {
_GET_PROXY_ABI(on_request_headers, _abi_02);
_GET_PROXY_ABI(on_response_headers, _abi_02);
_GET_PROXY(on_foreign_function);
} else if (abiVersion() == AbiVersion::ProxyWasm_0_2_100) {
_GET_PROXY_ABI(on_request_headers, _abi_03);
}
#undef _GET_PROXY_ABI
#undef _GET_PROXY
Expand Down