Skip to content

support data injection #7

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions include/proxy-wasm/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ class ContextBase : public RootInterface,
std::string_view /* details */) override {
return unimplemented();
}

// Inject Data
WasmResult injectEncodedDataToFilterChain(std::string_view /* body_text */, bool /* end_stream */) override {
return unimplemented();
}

void clearRouteCache() override { unimplemented(); }
void failStream(WasmStreamType stream_type) override { closeStream(stream_type); }

Expand Down
3 changes: 3 additions & 0 deletions include/proxy-wasm/context_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ struct HttpInterface {

// Call just before the Context is deleted. See RootInterface.
virtual void onDelete() = 0;

// Inject encoded data to filter chain
virtual WasmResult injectEncodedDataToFilterChain(std::string_view /* body_text */, bool /* end_stream */) = 0;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion include/proxy-wasm/exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Word send_local_response(Word response_code, Word response_code_details_ptr,
Word response_code_details_size, Word body_ptr, Word body_size,
Word additional_response_header_pairs_ptr,
Word additional_response_header_pairs_size, Word grpc_status);
Word inject_encoded_data_to_filter_chain(Word body_ptr, Word body_size, Word end_stream);
Word clear_route_cache();
Word get_shared_data(Word key_ptr, Word key_size, Word value_ptr_ptr, Word value_size_ptr,
Word cas_ptr);
Expand Down Expand Up @@ -173,7 +174,7 @@ Word wasi_unstable_path_filestat_get(Word fd, Word flags, Word path, Word path_l
_f(increment_metric) _f(record_metric) _f(get_metric) \
_f(set_effective_context) _f(done) \
_f(call_foreign_function) _f(redis_init) \
_f(redis_call)
_f(redis_call) _f(inject_encoded_data_to_filter_chain)

#define FOR_ALL_HOST_FUNCTIONS_ABI_SPECIFIC(_f) \
_f(get_configuration) _f(continue_request) _f(continue_response) _f(clear_route_cache) \
Expand Down
5 changes: 5 additions & 0 deletions include/proxy-wasm/wasm_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ proxy_send_local_response(uint32_t response_code, const char *response_code_deta
WR(body_ptr), WS(body_size), WR(additional_response_header_pairs_ptr),
WS(additional_response_header_pairs_size), WS(grpc_status)));
}
inline WasmResult
proxy_inject_encoded_data_to_filter_chain(const char *body_ptr, size_t body_size, bool end_stream) {
return wordToWasmResult(exports::inject_encoded_data_to_filter_chain(
WR(body_ptr), WS(body_size), WS(end_stream)));
}

inline WasmResult proxy_clear_route_cache() {
return wordToWasmResult(exports::clear_route_cache());
Expand Down
10 changes: 10 additions & 0 deletions src/exports.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ Word send_local_response(Word response_code, Word response_code_details_ptr,
return WasmResult::Ok;
}

Word inject_encoded_data_to_filter_chain(Word body_ptr, Word body_size, Word end_stream) {
auto *context = contextOrEffectiveContext();
auto body = context->wasmVm()->getMemory(body_ptr, body_size);
if (!body) {
return WasmResult::InvalidMemoryAccess;
}
context->injectEncodedDataToFilterChain(body.value(), end_stream != 0U);
return WasmResult::Ok;
}

Word clear_route_cache() {
auto *context = contextOrEffectiveContext();
context->clearRouteCache();
Expand Down
1 change: 1 addition & 0 deletions src/wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ void WasmBase::registerCallbacks() {
_REGISTER_PROXY(get_log_level);
_REGISTER_PROXY(redis_init);
_REGISTER_PROXY(redis_call);
_REGISTER_PROXY(inject_encoded_data_to_filter_chain);
}
#undef _REGISTER_PROXY

Expand Down
Loading