internal redirects: support passing headers from response to request (#30793)

* internal redirects: Support passing headers from response to request

This adds a new (repeated) field in the internal redirect policy,
"response_headers_to_preserve".  When set, the headers named there
will be copied from the response that triggers an internal redirect
into the request that follows.

This allows some limited information passing through the internal
redirect system.

The current system is faithful to the idea that internal redirects are
purely a latency optimization, and should behave similarly to if the
redirect had been passed to the downstream user-agent. This does
violate that idea.

Other proxies, such as Nginx, have a much more flexible way of
handling internal redirects that allows a fair bit of information
passing like this. This should allow implementations to adopt Envoy
that are using this kind of information passing, with reduced needs to
rearchitect.

Fixes: #30441
Fixes: #16777

Signed-off-by: Ryan Anderson <ryan.anderson@snowflake.com>
Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Switching loops to references

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Clarify that downstream filters will not run

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Use a vector of LowerCaseStrings

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Format fixes

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Fully qualify 'downstream_'

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Rename from ..._to_preserve to ..._to_copy

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Reject configs that specify HTTP/2 style headers or Host

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Fight with clang-tidy by hand

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Fixup bad doc references

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* punctuation

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* More doc fixups

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Add a small comment about request_headers_to_copy_

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Rip out the complicated header copying/restore logic and replace

This removes the existing specialized save/restore logic in favor of
just copying every header into another map, updating the original map
with the necessary changes, and then restoring the whole thing later on.

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Use copyFrom() instead of doing it by hand

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Return a reference instead of copying

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Deauto things

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* fight with clang-format

Signed-off-by: Ryan Anderson <ryan@michonline.com>

* Just use copyFrom()

Signed-off-by: Ryan Anderson <ryan@michonline.com>

---------

Signed-off-by: Ryan Anderson <ryan.anderson@snowflake.com>
Signed-off-by: Ryan Anderson <ryan@michonline.com>

Mirrored from https://github.com/envoyproxy/envoy @ 65bbace5fb0647ac6edc338c62cfc8fc69fda36e
main
update-envoy[bot] 1 year ago
parent 3ca196f8dc
commit 9e1c1c56ce
  1. 9
      envoy/config/route/v3/route_components.proto

@ -2365,6 +2365,7 @@ message QueryParameterMatcher {
}
// HTTP Internal Redirect :ref:`architecture overview <arch_overview_internal_redirects>`.
// [#next-free-field: 6]
message InternalRedirectPolicy {
// An internal redirect is not handled, unless the number of previous internal redirects that a
// downstream request has encountered is lower than this value.
@ -2390,6 +2391,14 @@ message InternalRedirectPolicy {
// Allow internal redirect to follow a target URI with a different scheme than the value of
// x-forwarded-proto. The default is false.
bool allow_cross_scheme_redirect = 4;
// Specifies a list of headers, by name, to copy from the internal redirect into the subsequent
// request. If a header is specified here but not present in the redirect, it will be cleared in
// the subsequent request.
repeated string response_headers_to_copy = 5 [(validate.rules).repeated = {
unique: true
items {string {well_known_regex: HTTP_HEADER_NAME strict: false}}
}];
}
// A simple wrapper for an HTTP filter config. This is intended to be used as a wrapper for the

Loading…
Cancel
Save