You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
can't get any informations from request header when process request body ? (ext_proc) #15569
area/ext_procquestionQuestions that are neither investigations, bugs, nor enhancementsstalestalebot believes this issue/PR has not been touched recently
I'm using ext_proc to implement some functions with ext_proc. An important case is that I want to get request_headers when I process request_body, but I can't. Is there any solution?
That's why the filter uses a gRPC stream. The idea is that your external processor will first receive a request_headers message, send back a reply, and then receive a request_body message. If it needs access to the request headers while processing the body, it needs to store them. However, since the request headers and body both arrive on the same stream, it's usually fairly easy to just store whatever information you need in a local variable.
Hope that helps, and if not then I think we need to do a better job on examples.
I got another question like this.
If I change request_body, from json to xml, the request_body's length has been changed, but "content-length" in request_header is still the old one. So, the client can't get the request correctly. The same situation is with "change response-body but 'conent-length' in response_header is still".
I have no idea about this. How can I change the Headers after I changed the Body? Could I get some advice? @gbrail Thanks.
I would like, someday, to be able to change headers after examining or
modifying the body. However, right now that isn't possible -- it might
require some changes to how HTTP filters are handled and I don't know
whether that will be possible.
For this particular case, however, the solution isn't too bad -- if you
think you're going to modify the body, then REMOVE the content-length
header when you process the headers. Envoy will fix it before it sends the
request or response on its way so that it matches the HTTP protocol.
@gbrail I have a similar issue except instead of content-length theres a value in the header that is calculated based off of the body and it needs to match (crc32). Since I want to modify the body I would need to change that header value. It sounds like this is not possible in the ext_proc filter. Do you know if that is a limitation of just this filter or would the other ones that can process the body (lua / WASM) also have this limitation?
Is there a way to maybe buffer and not send out the headers right away with the async option and wait for the body to come in?
I'm not sure that you'd be able to do that in any Envoy filter right now -- but if someone does it then we can certainly add that capability to ext_proc.
The problem is that you want Envoy to hold the filter chain "in place" and not transmit the headers to other filters in the chain until the body callbacks have been run. I don't know of a way to do that in Envoy's HTTP filter chain today. You can stop the filters from being further processed by returning a status like "StopAllIterationAndWatermark," but when the filter calls the "continue" function Envoy will process the headers further down or up the filter chain before sending the data, so by the time the data arrives the headers have already been sent off.
If we can figure out a way around this then I can certainly implement a change in ext_proc.
Performing an outbound async HTTP call to an upstream host. Such a call can be performed while buffering body data so that when the call completes upstream headers can be modified.
This seems like what I need, just not yet implemented in the ext_proc if I understand?
So the short answer is just to return StopIteration rather than StopAllIterationAndWatermark from decode/encodeHeaders. But that's the short answer. ext_proc lets the processing server decide in each callback what callbacks it wants next, so if we return StopIteration then Envoy will likely call encode/decodeData before the gRPC message has come back (if it was ever sent at all) and we don't know whether to dispatch a gRPC there or not. So we need to stop iteration there too, and probably buffer, but don't want to fill the buffer if the processor isn't going to want the body. So when the gRPC response comes back we now need to consider three or four different things to determine what to do next, and so on and so on.
The result is a state machine that changes from 2-3 states to many more. I'll have to draw it out and refactor the code and experiment and things, so this will likely take a while.
@gbrail Would implementing request trailers and response trailers in ext_proc be a solution to this? From what I've been reading it seems that's what they are for, if thats easier than adding functionality to be able to change the headers in the body.
If your application can work with trailers, then trailers are great.
ext_proc needs to have support for trailers but there are some nuances --
like how to behave when a processor wants to add trailers but they're not
there already. It's on the list of things that I know we need to add.
Also, from what I can see, Envoy only implements trailers for HTTP/2. That
might also affect whether it works for you.
As for why response headers aren't being sent -- they should be sent unless the processor closed the stream on the other end, or unless the gRPC timed out. In the event of a timeout an error should be returned to the client unless "failure_mode_allow" is set. Turning on "filter" tracing or debugging, for instance with the command-line option:
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.
This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions.
area/ext_procquestionQuestions that are neither investigations, bugs, nor enhancementsstalestalebot believes this issue/PR has not been touched recently
Activity
snowp commentedon Mar 19, 2021
@gbrail
gbrail commentedon Mar 19, 2021
Glad you're interested in the new filter!
That's why the filter uses a gRPC stream. The idea is that your external processor will first receive a request_headers message, send back a reply, and then receive a request_body message. If it needs access to the request headers while processing the body, it needs to store them. However, since the request headers and body both arrive on the same stream, it's usually fairly easy to just store whatever information you need in a local variable.
Hope that helps, and if not then I think we need to do a better job on examples.
jefflaifu commentedon Mar 22, 2021
Got it!
I'm new to gRPC, and not familiar with Go. I'm using Java to implement ext_proc.
I think I am right with the code below:
jefflaifu commentedon Mar 24, 2021
I got another question like this.
If I change request_body, from json to xml, the request_body's length has been changed, but "content-length" in request_header is still the old one. So, the client can't get the request correctly. The same situation is with "change response-body but 'conent-length' in response_header is still".
I have no idea about this. How can I change the Headers after I changed the Body? Could I get some advice?
@gbrail Thanks.
gbrail commentedon Mar 24, 2021
dragonbone81 commentedon Mar 31, 2021
@gbrail I have a similar issue except instead of content-length theres a value in the header that is calculated based off of the body and it needs to match (crc32). Since I want to modify the body I would need to change that header value. It sounds like this is not possible in the ext_proc filter. Do you know if that is a limitation of just this filter or would the other ones that can process the body (lua / WASM) also have this limitation?
Is there a way to maybe buffer and not send out the headers right away with the async option and wait for the body to come in?
gbrail commentedon Mar 31, 2021
I'm not sure that you'd be able to do that in any Envoy filter right now -- but if someone does it then we can certainly add that capability to ext_proc.
The problem is that you want Envoy to hold the filter chain "in place" and not transmit the headers to other filters in the chain until the body callbacks have been run. I don't know of a way to do that in Envoy's HTTP filter chain today. You can stop the filters from being further processed by returning a status like "StopAllIterationAndWatermark," but when the filter calls the "continue" function Envoy will process the headers further down or up the filter chain before sending the data, so by the time the data arrives the headers have already been sent off.
If we can figure out a way around this then I can certainly implement a change in ext_proc.
dragonbone81 commentedon Mar 31, 2021
Is what is mentioned here in the Lua section what you mean:
https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/lua_filter#currently-supported-high-level-features
This seems like what I need, just not yet implemented in the ext_proc if I understand?
gbrail commentedon Mar 31, 2021
Well if it works in that filter there must be a way, so I'll read the code and figure out what they did.
gbrail commentedon Apr 1, 2021
So the short answer is just to return StopIteration rather than StopAllIterationAndWatermark from decode/encodeHeaders. But that's the short answer. ext_proc lets the processing server decide in each callback what callbacks it wants next, so if we return StopIteration then Envoy will likely call encode/decodeData before the gRPC message has come back (if it was ever sent at all) and we don't know whether to dispatch a gRPC there or not. So we need to stop iteration there too, and probably buffer, but don't want to fill the buffer if the processor isn't going to want the body. So when the gRPC response comes back we now need to consider three or four different things to determine what to do next, and so on and so on.
The result is a state machine that changes from 2-3 states to many more. I'll have to draw it out and refactor the code and experiment and things, so this will likely take a while.
dragonbone81 commentedon Apr 1, 2021
@gbrail Thanks for taking this on so quick :) Seems like there is a path forward so far for making this work. Really liking this ext_proc filter!
dragonbone81 commentedon Apr 2, 2021
@gbrail Would implementing request trailers and response trailers in ext_proc be a solution to this? From what I've been reading it seems that's what they are for, if thats easier than adding functionality to be able to change the headers in the body.
gbrail commentedon Apr 3, 2021
RameshByndoor commentedon Apr 15, 2021
@gbrail Hi any idea why case RESPONSE_HEADERS: doesn't get called.? I have response_header_mode: "SEND" set in filter http.ext_proc
gbrail commentedon Apr 16, 2021
The PR is in progress:
#15935
As for why response headers aren't being sent -- they should be sent unless the processor closed the stream on the other end, or unless the gRPC timed out. In the event of a timeout an error should be returned to the client unless "failure_mode_allow" is set. Turning on "filter" tracing or debugging, for instance with the command-line option:
may also help you understand what's going on.
gbrail commentedon May 10, 2021
Support for modifying the headers along with the body when the filter is in "BUFFERED" mode was added in #15935.
github-actions commentedon Jun 9, 2021
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.
github-actions commentedon Jun 16, 2021
This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions.