Skip to content

Enable header modifications with body in "buffered" mode - #15935

Merged
htuch merged 3 commits into
envoyproxy:mainfrom
gbrail:ext-proc-body-1
Apr 20, 2021
Merged

htuch merged 3 commits into
envoyproxy:mainfrom
gbrail:ext-proc-body-1

Conversation

@gbrail

@gbrail gbrail commented Apr 13, 2021

Copy link
Copy Markdown
Contributor

Commit message: Make it possible to process header mutations
along with body mutations when the body is in "BUFFERED" mode.

Additional Description: This works by returning "StopIteration"
after the headers have been processed until a response comes
back from the "headers" message. The body is watermarked in the
meantime. As a result, large bodies will still stream through
without exceeding the buffer limit when the body mode is not
"BUFFERED."

Risk Level: Medium. Changes how bodies are handled.

Testing: Existing unit and integration tests, plus some
manual verification using external servers.

Release Notes: Servers for the ext_proc filter can now use the HeaderMutation message when sending back a response to a request_body or response_body message to change headers at the same time as the body. This is only possible when the BodySendMode is BUFFERED.

Signed-off-by: Gregory Brail [email protected]

Commit message: Make it possible to process header mutations
along with body mutations when the body is in "BUFFERED" mode.

Additional description: This works by returning "StopIteration"
after the headers have been processed until a response comes
back from the "headers" message. The body is watermarked in the
meantime. As a result, large bodies will still stream through
without exceeding the buffer limit when the body mode is not
"BUFFERED."

Risk Level: Medium. Changes how bodies are handled.

Testing: Existing unit and integration tests, plus some
manual verification using external servers.

Signed-off-by: Gregory Brail <[email protected]>
@gbrail
gbrail marked this pull request as ready for review April 13, 2021 17:00
@gbrail
gbrail requested a review from snowp as a code owner April 13, 2021 17:00
@htuch htuch assigned snowp and htuch Apr 13, 2021

@snowp snowp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Nice addition, left some comments to get you started

@snowp snowp added the waiting label Apr 14, 2021

@snowp snowp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks this looks pretty good, just one question

// Otherwise, we're not ready to continue processing because then
// we won't be able to modify the headers any more, so do nothing and
// let the doData callback handle body chunks until the end is reached.
return true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, shouldn't this be false to indicate that we did not process the message? I don't recall how this was in the previous iteration, but now it seems like we return true regardless of what body_send_deferred_ is set to?

Should there be a return after L42?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contract for this function, which is called from "onReceiveMessage" in ext_proc.cc, is that it returns false if the message is unexpected (aka spurious). So it's correct to return true in this case, and that's how it's worked for a long time.

In that particular case -- line 48 -- a "headers response" came back from the server in response to a previous headers request. The processor requested to buffer the body, but the entire body hadn't been received by the filter yet, which is why "body_send_deferred_" is false. The filter needs to continue buffering the body until the end of stream is reached, at which point it will send the body to the server. So yes, that's correct in this case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! I saw

    message_handled = decoding_state_.handleHeadersResponse(response->request_headers());

and it made me think that we were going to return false in this case since we hadn't been able to "handle" the response (due to the body not being fully buffered). Your explanation makes sense though, thanks for that!

@snowp snowp added the waiting label Apr 19, 2021
@htuch
htuch merged commit 457238e into envoyproxy:main Apr 20, 2021
gokulnair pushed a commit to gokulnair/envoy that referenced this pull request May 6, 2021
…15935)

This works by returning "StopIteration"
after the headers have been processed until a response comes
back from the "headers" message. The body is watermarked in the
meantime. As a result, large bodies will still stream through
without exceeding the buffer limit when the body mode is not
"BUFFERED."

Risk Level: Medium. Changes how bodies are handled.

Testing: Existing unit and integration tests, plus some
manual verification using external servers.

Release Notes: Servers for the ext_proc filter can now use the HeaderMutation message when sending back a response to a request_body or response_body message to change headers at the same time as the body. This is only possible when the BodySendMode is BUFFERED.

Signed-off-by: Gregory Brail <[email protected]>
Signed-off-by: Gokul Nair <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants