-
Notifications
You must be signed in to change notification settings - Fork 74
feat: add knob to customise on{Request,Response}Headers StopIteration behavior #434
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
Merged
mpwarres
merged 7 commits into
proxy-wasm:main
from
mpwarres:request-headers-stop-iteration
Jul 13, 2025
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
02239af
feat: add knob to customise onRequestHeaders StopIteration behavior
mpwarres 1afe902
Fix test copy-paste error
mpwarres 769b7bd
rename to allow_on_headers_stop_iteration
mpwarres b9815c7
no-op comment change to trigger workflow retry
mpwarres c279c7f
Merge branch 'main' into request-headers-stop-iteration
mpwarres 7e52561
apply clang-format-12
mpwarres 6c906aa
move test case wasm_handle and plugin_handle to proper scope
mpwarres File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "gtest/gtest.h" | ||
#include "include/proxy-wasm/wasm.h" | ||
#include "test/utility.h" | ||
|
||
namespace proxy_wasm { | ||
|
||
INSTANTIATE_TEST_SUITE_P(WasmEngines, TestVm, testing::ValuesIn(getWasmEngines()), | ||
[](const testing::TestParamInfo<std::string> &info) { | ||
return info.param; | ||
}); | ||
|
||
// TestVm is parameterized for each engine and creates a VM on construction. | ||
TEST_P(TestVm, AllowOnRequestHeadersStopIteration) { | ||
// Read the wasm source. | ||
auto source = readTestWasmFile("stop_iteration.wasm"); | ||
ASSERT_FALSE(source.empty()); | ||
|
||
// Create a WasmBase and load the plugin. | ||
auto wasm = std::make_shared<TestWasm>(std::move(vm_)); | ||
ASSERT_TRUE(wasm->load(source, /*allow_precompiled=*/false)); | ||
ASSERT_TRUE(wasm->initialize()); | ||
|
||
// Create a plugin. | ||
const auto plugin = std::make_shared<PluginBase>( | ||
/*name=*/"test", /*root_id=*/"", /*vm_id=*/"", | ||
/*engine=*/wasm->wasm_vm()->getEngineName(), /*plugin_config=*/"", | ||
/*fail_open=*/false, /*key=*/""); | ||
|
||
// Create root context, call onStart(). | ||
ContextBase *root_context = wasm->start(plugin); | ||
ASSERT_TRUE(root_context != nullptr); | ||
|
||
// On the root context, call onConfigure(). | ||
ASSERT_TRUE(wasm->configure(root_context, plugin)); | ||
|
||
// By default, stream context onRequestHeaders translates | ||
// FilterHeadersStatus::StopIteration to | ||
// FilterHeadersStatus::StopAllIterationAndWatermark. | ||
{ | ||
auto wasm_handle = std::make_shared<WasmHandleBase>(wasm); | ||
auto plugin_handle = std::make_shared<PluginHandleBase>(wasm_handle, plugin); | ||
auto stream_context = TestContext(wasm.get(), root_context->id(), plugin_handle); | ||
stream_context.onCreate(); | ||
EXPECT_EQ(stream_context.onRequestHeaders(/*headers=*/0, /*end_of_stream=*/false), | ||
FilterHeadersStatus::StopAllIterationAndWatermark); | ||
stream_context.onResponseHeaders(/*headers=*/0, /*end_of_stream=*/false); | ||
stream_context.onDone(); | ||
stream_context.onDelete(); | ||
} | ||
ASSERT_FALSE(wasm->isFailed()); | ||
|
||
// Create a stream context that propagates FilterHeadersStatus::StopIteration. | ||
{ | ||
auto wasm_handle = std::make_shared<WasmHandleBase>(wasm); | ||
auto plugin_handle = std::make_shared<PluginHandleBase>(wasm_handle, plugin); | ||
auto stream_context = TestContext(wasm.get(), root_context->id(), plugin_handle); | ||
stream_context.set_allow_on_request_headers_stop_iteration(true); | ||
stream_context.onCreate(); | ||
EXPECT_EQ(stream_context.onRequestHeaders(/*headers=*/0, /*end_of_stream=*/false), | ||
FilterHeadersStatus::StopIteration); | ||
stream_context.onResponseHeaders(/*headers=*/0, /*end_of_stream=*/false); | ||
stream_context.onDone(); | ||
stream_context.onDelete(); | ||
} | ||
ASSERT_FALSE(wasm->isFailed()); | ||
} | ||
|
||
} // namespace proxy_wasm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "proxy_wasm_intrinsics.h" | ||
|
||
class StopIterationContext : public Context { | ||
public: | ||
explicit StopIterationContext(uint32_t id, RootContext *root) : Context(id, root) {} | ||
|
||
FilterHeadersStatus onRequestHeaders(uint32_t headers, bool end_of_stream) override { | ||
return FilterHeadersStatus::StopIteration; | ||
} | ||
}; | ||
|
||
static RegisterContextFactory register_StaticContext(CONTEXT_FACTORY(StopIterationContext), | ||
ROOT_FACTORY(RootContext)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.