Skip to content

Commit b55f5ba

Browse files
authored
Pass end_of-stream flag to request and response headers. (proxy-wasm#24)
This propagates the end_of_stream flag to the plugin for both of the header callbacks. Signed-off-by: Gregory Brail <[email protected]>
1 parent 65652f0 commit b55f5ba

File tree

5 files changed

+38
-33
lines changed

5 files changed

+38
-33
lines changed

WORKSPACE

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
55

66
git_repository(
77
name = "proxy_wasm_cpp_sdk",
8+
commit = "b273b07ae0cfa9cc76dfe38236b163e9e3a2ab49",
89
remote = "https://github.com/proxy-wasm/proxy-wasm-cpp-sdk",
9-
commit = "96927d814b3ec14893b56793e122125e095654c7",
1010
)
1111

1212
http_archive(
@@ -20,19 +20,21 @@ http_archive(
2020
# required by com_google_protobuf
2121
http_archive(
2222
name = "bazel_skylib",
23+
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
2324
urls = [
2425
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
2526
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
26-
],
27-
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
28-
)
27+
],
28+
)
29+
2930
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
31+
3032
bazel_skylib_workspace()
3133

3234
git_repository(
3335
name = "com_google_protobuf",
34-
remote = "https://github.com/protocolbuffers/protobuf",
3536
commit = "655310ca192a6e3a050e0ca0b7084a2968072260",
37+
remote = "https://github.com/protocolbuffers/protobuf",
3638
)
3739

3840
http_archive(

include/proxy-wasm/null_plugin.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717

1818
#include <memory>
1919

20+
#include "google/protobuf/message.h"
2021
#include "include/proxy-wasm/null_vm_plugin.h"
2122
#include "include/proxy-wasm/wasm.h"
2223

23-
#include "google/protobuf/message.h"
24-
2524
namespace proxy_wasm {
2625
namespace null_plugin {
2726
#include "proxy_wasm_enums.h"
@@ -84,12 +83,12 @@ class NullPlugin : public NullVmPlugin {
8483
void onDownstreamConnectionClose(uint64_t context_id, uint64_t close_type);
8584
void onUpstreamConnectionClose(uint64_t context_id, uint64_t close_type);
8685

87-
uint64_t onRequestHeaders(uint64_t context_id, uint64_t headers);
86+
uint64_t onRequestHeaders(uint64_t context_id, uint64_t headers, uint64_t end_of_stream);
8887
uint64_t onRequestBody(uint64_t context_id, uint64_t body_buffer_length, uint64_t end_of_stream);
8988
uint64_t onRequestTrailers(uint64_t context_id, uint64_t trailers);
9089
uint64_t onRequestMetadata(uint64_t context_id, uint64_t elements);
9190

92-
uint64_t onResponseHeaders(uint64_t context_id, uint64_t headers);
91+
uint64_t onResponseHeaders(uint64_t context_id, uint64_t headers, uint64_t end_of_stream);
9392
uint64_t onResponseBody(uint64_t context_id, uint64_t body_buffer_length, uint64_t end_of_stream);
9493
uint64_t onResponseTrailers(uint64_t context_id, uint64_t trailers);
9594
uint64_t onResponseMetadata(uint64_t context_id, uint64_t elements);

include/proxy-wasm/wasm.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
#include <atomic>
2121
#include <deque>
2222
#include <map>
23+
#include <memory>
2324
#include <unordered_map>
2425
#include <unordered_set>
25-
#include <memory>
2626

2727
#include "include/proxy-wasm/compat.h"
28-
2928
#include "include/proxy-wasm/context.h"
3029
#include "include/proxy-wasm/exports.h"
3130
#include "include/proxy-wasm/wasm_vm.h"
@@ -206,12 +205,12 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
206205
WasmCallVoid<2> on_downstream_connection_close_;
207206
WasmCallVoid<2> on_upstream_connection_close_;
208207

209-
WasmCallWord<2> on_request_headers_;
208+
WasmCallWord<3> on_request_headers_;
210209
WasmCallWord<3> on_request_body_;
211210
WasmCallWord<2> on_request_trailers_;
212211
WasmCallWord<2> on_request_metadata_;
213212

214-
WasmCallWord<2> on_response_headers_;
213+
WasmCallWord<3> on_response_headers_;
215214
WasmCallWord<3> on_response_body_;
216215
WasmCallWord<2> on_response_trailers_;
217216
WasmCallWord<2> on_response_metadata_;

src/context.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,15 @@ void ContextBase::onUpstreamConnectionClose(CloseType close_type) {
387387
// Empty headers/trailers have zero size.
388388
template <typename P> static uint32_t headerSize(const P &p) { return p ? p->size() : 0; }
389389

390-
FilterHeadersStatus ContextBase::onRequestHeaders(uint32_t headers, bool) {
390+
FilterHeadersStatus ContextBase::onRequestHeaders(uint32_t headers, bool end_of_stream) {
391391
DeferAfterCallActions actions(this);
392392
onCreate(root_context_id_);
393393
in_vm_context_created_ = true;
394394
if (!wasm_->on_request_headers_) {
395395
return FilterHeadersStatus::Continue;
396396
}
397-
auto result = wasm_->on_request_headers_(this, id_, headers).u64_;
397+
auto result =
398+
wasm_->on_request_headers_(this, id_, headers, static_cast<uint32_t>(end_of_stream)).u64_;
398399
if (result > static_cast<uint64_t>(FilterHeadersStatus::StopAllIterationAndWatermark))
399400
return FilterHeadersStatus::StopAllIterationAndWatermark;
400401
return static_cast<FilterHeadersStatus>(result);
@@ -436,7 +437,7 @@ FilterMetadataStatus ContextBase::onRequestMetadata(uint32_t elements) {
436437
return FilterMetadataStatus::Continue; // This is currently the only return code.
437438
}
438439

439-
FilterHeadersStatus ContextBase::onResponseHeaders(uint32_t headers, bool) {
440+
FilterHeadersStatus ContextBase::onResponseHeaders(uint32_t headers, bool end_of_stream) {
440441
DeferAfterCallActions actions(this);
441442
if (!in_vm_context_created_) {
442443
// If the request is invalid then onRequestHeaders() will not be called and neither will
@@ -449,7 +450,8 @@ FilterHeadersStatus ContextBase::onResponseHeaders(uint32_t headers, bool) {
449450
if (!wasm_->on_response_headers_) {
450451
return FilterHeadersStatus::Continue;
451452
}
452-
auto result = wasm_->on_response_headers_(this, id_, headers).u64_;
453+
auto result =
454+
wasm_->on_response_headers_(this, id_, headers, static_cast<uint32_t>(end_of_stream)).u64_;
453455
if (result > static_cast<uint64_t>(FilterHeadersStatus::StopAllIterationAndWatermark))
454456
return FilterHeadersStatus::StopAllIterationAndWatermark;
455457
return static_cast<FilterHeadersStatus>(result);

src/null/null_plugin.cc

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
#include "include/proxy-wasm/null_plugin.h"
17-
1816
#include <stdint.h>
1917
#include <stdio.h>
2018

@@ -25,6 +23,7 @@
2523
#include <utility>
2624
#include <vector>
2725

26+
#include "include/proxy-wasm/null_plugin.h"
2827
#include "include/proxy-wasm/null_vm.h"
2928
#include "include/proxy-wasm/wasm.h"
3029

@@ -175,11 +174,6 @@ void NullPlugin::getFunction(string_view function_name, WasmCallWord<2> *f) {
175174
SaveRestoreContext saved_context(context);
176175
return Word(plugin->validateConfiguration(context_id, configuration_size));
177176
};
178-
} else if (function_name == "proxy_on_request_headers") {
179-
*f = [plugin](ContextBase *context, Word context_id, Word headers) -> Word {
180-
SaveRestoreContext saved_context(context);
181-
return Word(plugin->onRequestHeaders(context_id, headers));
182-
};
183177
} else if (function_name == "proxy_on_request_trailers") {
184178
*f = [plugin](ContextBase *context, Word context_id, Word trailers) -> Word {
185179
SaveRestoreContext saved_context(context);
@@ -190,11 +184,6 @@ void NullPlugin::getFunction(string_view function_name, WasmCallWord<2> *f) {
190184
SaveRestoreContext saved_context(context);
191185
return Word(plugin->onRequestMetadata(context_id, elements));
192186
};
193-
} else if (function_name == "proxy_on_response_headers") {
194-
*f = [plugin](ContextBase *context, Word context_id, Word headers) -> Word {
195-
SaveRestoreContext saved_context(context);
196-
return Word(plugin->onResponseHeaders(context_id, headers));
197-
};
198187
} else if (function_name == "proxy_on_response_trailers") {
199188
*f = [plugin](ContextBase *context, Word context_id, Word trailers) -> Word {
200189
SaveRestoreContext saved_context(context);
@@ -225,12 +214,22 @@ void NullPlugin::getFunction(string_view function_name, WasmCallWord<3> *f) {
225214
SaveRestoreContext saved_context(context);
226215
return Word(plugin->onUpstreamData(context_id, body_buffer_length, end_of_stream));
227216
};
217+
} else if (function_name == "proxy_on_request_headers") {
218+
*f = [plugin](ContextBase *context, Word context_id, Word headers, Word end_of_stream) -> Word {
219+
SaveRestoreContext saved_context(context);
220+
return Word(plugin->onRequestHeaders(context_id, headers, end_of_stream));
221+
};
228222
} else if (function_name == "proxy_on_request_body") {
229223
*f = [plugin](ContextBase *context, Word context_id, Word body_buffer_length,
230224
Word end_of_stream) -> Word {
231225
SaveRestoreContext saved_context(context);
232226
return Word(plugin->onRequestBody(context_id, body_buffer_length, end_of_stream));
233227
};
228+
} else if (function_name == "proxy_on_response_headers") {
229+
*f = [plugin](ContextBase *context, Word context_id, Word headers, Word end_of_stream) -> Word {
230+
SaveRestoreContext saved_context(context);
231+
return Word(plugin->onResponseHeaders(context_id, headers, end_of_stream));
232+
};
234233
} else if (function_name == "proxy_on_response_body") {
235234
*f = [plugin](ContextBase *context, Word context_id, Word body_buffer_length,
236235
Word end_of_stream) -> Word {
@@ -384,8 +383,10 @@ void NullPlugin::onUpstreamConnectionClose(uint64_t context_id, uint64_t close_t
384383
getContext(context_id)->onUpstreamConnectionClose(static_cast<PeerType>(close_type));
385384
}
386385

387-
uint64_t NullPlugin::onRequestHeaders(uint64_t context_id, uint64_t headers) {
388-
return static_cast<uint64_t>(getContext(context_id)->onRequestHeaders(headers));
386+
uint64_t NullPlugin::onRequestHeaders(uint64_t context_id, uint64_t headers,
387+
uint64_t end_of_stream) {
388+
return static_cast<uint64_t>(
389+
getContext(context_id)->onRequestHeaders(headers, end_of_stream != 0));
389390
}
390391

391392
uint64_t NullPlugin::onRequestBody(uint64_t context_id, uint64_t body_buffer_length,
@@ -403,8 +404,10 @@ uint64_t NullPlugin::onRequestMetadata(uint64_t context_id, uint64_t elements) {
403404
return static_cast<uint64_t>(getContext(context_id)->onRequestMetadata(elements));
404405
}
405406

406-
uint64_t NullPlugin::onResponseHeaders(uint64_t context_id, uint64_t headers) {
407-
return static_cast<uint64_t>(getContext(context_id)->onResponseHeaders(headers));
407+
uint64_t NullPlugin::onResponseHeaders(uint64_t context_id, uint64_t headers,
408+
uint64_t end_of_stream) {
409+
return static_cast<uint64_t>(
410+
getContext(context_id)->onResponseHeaders(headers, end_of_stream != 0));
408411
}
409412

410413
uint64_t NullPlugin::onResponseBody(uint64_t context_id, uint64_t body_buffer_length,

0 commit comments

Comments
 (0)