Skip to content

Commit

Permalink
fix data buffer of wasm filter
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlanni committed Nov 25, 2024
1 parent 13aee61 commit 440fb1b
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion source/extensions/common/wasm/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,17 @@ Http::FilterDataStatus Context::decodeData(::Envoy::Buffer::Instance& data, bool
#endif
return Http::FilterDataStatus::Continue;
}
if (buffering_request_body_) {
decoder_callbacks_->addDecodedData(data, false);
if (destroyed_) {
// The data adding have triggered a local reply (413) and we needn't to continue to
// call the VM.
// Note this is not perfect way. If the local reply processing is stopped by other
// filters, this filter will still try to call the VM. But at least we can ensure
// the VM has valid context.
return Http::FilterDataStatus::StopIterationAndBuffer;
}
}
request_body_buffer_ = &data;
end_of_stream_ = end_stream;
const auto buffer = getBuffer(WasmBufferType::HttpRequestBody);
Expand Down Expand Up @@ -2020,6 +2031,17 @@ Http::FilterDataStatus Context::encodeData(::Envoy::Buffer::Instance& data, bool
#endif
return Http::FilterDataStatus::Continue;
}
if (buffering_response_body_) {
encoder_callbacks_->addEncodedData(data, false);
if (destroyed_) {
// The data adding have triggered a local reply (413) and we needn't to continue to
// call the VM.
// Note this is not perfect way. If the local reply processing is stopped by other
// filters, this filter will still try to call the VM. But at least we can ensure
// the VM has valid context.
return Http::FilterDataStatus::StopIterationAndBuffer;
}
}
response_body_buffer_ = &data;
end_of_stream_ = end_stream;
const auto buffer = getBuffer(WasmBufferType::HttpResponseBody);
Expand All @@ -2028,7 +2050,7 @@ Http::FilterDataStatus Context::encodeData(::Envoy::Buffer::Instance& data, bool
buffering_response_body_ = false;
switch (result) {
case Http::FilterDataStatus::Continue:
request_body_buffer_ = nullptr;
response_body_buffer_ = nullptr;
break;
case Http::FilterDataStatus::StopIterationAndBuffer:
buffering_response_body_ = true;
Expand Down

0 comments on commit 440fb1b

Please sign in to comment.