envoyproxy / envoy

Cloud-native high-performance edge/middle/service proxy
https://www.envoyproxy.io
Apache License 2.0
25.07k stars 4.82k forks source link

How to invoke decodeData in a header-only request? #36692

Open Octopus409 opened 1 month ago

Octopus409 commented 1 month ago

I am writing a filter that can inject some data into body even it's a header-only request. I have tried call addDecodedData in decodeHeader() to add some data, but decodeData() has not been called later in the same filter. It seems that this will only take effect in subsequent filters.

I try addDecodeData in decodeHeader() look like this.

if(end_stream){
    // for header-only request, add an empty body frame to trigger decodeData()
    Envoy::Buffer::OwnedImpl buffer{"mark"};
    decoder_callbacks_->addDecodedData(buffer, true);
}
return  Http::FilterHeadersStatus::StopIteration;

I'm not sure if my understanding of addDecodedData is correct. Maybe I should add data in the previous filter and then my custom filter will invoke decodeData? Is there any way to invoke decodeData in the same filter?

tyxia commented 1 month ago

decodeData by design is invoked for body. i.e., not for header only request

Octopus409 commented 1 month ago

decodeData by design is invoked for body. i.e., not for header only request

thanks for your comment, you are right, invoke decodeData in a header only request is bit weird.

https://github.com/envoyproxy/envoy/blob/ee6163435be32f0efd3ad068e90ea89c974991c3/envoy/http/filter.h#L588 but I found this note in the decoder callback, which seems to support this special requirement.

tyxia commented 1 month ago

That is for subsequent filter not for the same filter

github-actions[bot] commented 4 days ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.

Octopus409 commented 4 days ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。