http: local reply mapper (#11007)

Allows to create custom mappers of response code based on access_log filters.
Allows to map error response to custom in Text or Json format.

Signed-off-by: Wayne Zhang <qiwzhang@google.com>

Mirrored from https://github.com/envoyproxy/envoy @ 74290ef76a76fbbf50f072dc33438791f93f68c7
master-ci-test
data-plane-api(CircleCI) 5 years ago
parent cf6e0b61d2
commit 9c48824ae4
  1. 6
      envoy/config/core/v3/substitution_format_string.proto
  2. 6
      envoy/config/core/v4alpha/substitution_format_string.proto
  3. 69
      envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto
  4. 75
      envoy/extensions/filters/network/http_connection_manager/v4alpha/http_connection_manager.proto

@ -25,7 +25,7 @@ message SubstitutionFormatString {
//
// .. code-block::
//
// text_format: %RESP_BODY%:%RESPONSE_CODE%:path=$REQ(:path)%
// text_format: %LOCAL_REPLY_BODY%:%RESPONSE_CODE%:path=$REQ(:path)%
//
// The following plain text will be created:
//
@ -43,9 +43,9 @@ message SubstitutionFormatString {
//
// .. code-block::
//
// typed_json_format:
// json_format:
// status: %RESPONSE_CODE%
// message: %RESP_BODY%
// message: %LOCAL_REPLY_BODY%
//
// The following JSON object would be created:
//

@ -29,7 +29,7 @@ message SubstitutionFormatString {
//
// .. code-block::
//
// text_format: %RESP_BODY%:%RESPONSE_CODE%:path=$REQ(:path)%
// text_format: %LOCAL_REPLY_BODY%:%RESPONSE_CODE%:path=$REQ(:path)%
//
// The following plain text will be created:
//
@ -47,9 +47,9 @@ message SubstitutionFormatString {
//
// .. code-block::
//
// typed_json_format:
// json_format:
// status: %RESPONSE_CODE%
// message: %RESP_BODY%
// message: %LOCAL_REPLY_BODY%
//
// The following JSON object would be created:
//

@ -3,8 +3,10 @@ syntax = "proto3";
package envoy.extensions.filters.network.http_connection_manager.v3;
import "envoy/config/accesslog/v3/accesslog.proto";
import "envoy/config/core/v3/base.proto";
import "envoy/config/core/v3/config_source.proto";
import "envoy/config/core/v3/protocol.proto";
import "envoy/config/core/v3/substitution_format_string.proto";
import "envoy/config/route/v3/route.proto";
import "envoy/config/route/v3/scoped_route.proto";
import "envoy/config/trace/v3/http_tracer.proto";
@ -507,6 +509,11 @@ message HttpConnectionManager {
// 3. Tracing decision (sampled, forced, etc) is set in 14th byte of the UUID.
RequestIDExtension request_id_extension = 36;
// The configuration to customize local reply returned by Envoy. It can customize status code,
// body text and response content type. If not specified, status code and text body are hard
// coded in Envoy, the response content type is plain text.
LocalReplyConfig local_reply_config = 38;
// Determines if the port part should be removed from host/authority header before any processing
// of request by HTTP filters or routing. The port would be removed only if it is equal to the :ref:`listener's<envoy_api_field_config.listener.v3.Listener.address>`
// local port and request method is not CONNECT. This affects the upstream host header as well.
@ -516,6 +523,68 @@ message HttpConnectionManager {
bool strip_matching_host_port = 39;
}
// The configuration to customize local reply returned by Envoy.
message LocalReplyConfig {
// Configuration of list of mappers which allows to filter and change local response.
// The mappers will be checked by the specified order until one is matched.
repeated ResponseMapper mappers = 1;
// The configuration to form response body from the :ref:`command operators <config_access_log_command_operators>`
// and to specify response content type as one of: plain/text or application/json.
//
// Example one: plain/text body_format.
//
// .. code-block::
//
// text_format: %LOCAL_REPLY_BODY%:%RESPONSE_CODE%:path=$REQ(:path)%
//
// The following response body in `plain/text` format will be generated for a request with
// local reply body of "upstream connection error", response_code=503 and path=/foo.
//
// .. code-block::
//
// upstream connect error:503:path=/foo
//
// Example two: application/json body_format.
//
// .. code-block::
//
// json_format:
// status: %RESPONSE_CODE%
// message: %LOCAL_REPLY_BODY%
// path: $REQ(:path)%
//
// The following response body in "application/json" format would be generated for a request with
// local reply body of "upstream connection error", response_code=503 and path=/foo.
//
// .. code-block:: json
//
// {
// "status": 503,
// "message": "upstream connection error",
// "path": "/foo"
// }
//
config.core.v3.SubstitutionFormatString body_format = 2;
}
// The configuration to filter and change local response.
message ResponseMapper {
// Filter to determine if this mapper should apply.
config.accesslog.v3.AccessLogFilter filter = 1 [(validate.rules).message = {required: true}];
// The new response status code if specified.
google.protobuf.UInt32Value status_code = 2 [(validate.rules).uint32 = {lt: 600 gte: 200}];
// The new local reply body text if specified. It will be used in the `%LOCAL_REPLY_BODY%`
// command operator in the `body_foramt`.
config.core.v3.DataSource body = 3;
// A per mapper `body_format` to override the :ref:`body_format <envoy_v3_api_field_extensions.filters.network.http_connection_manager.v3.LocalReplyConfig.body_format>`.
// It will be used when this mapper is matched.
config.core.v3.SubstitutionFormatString body_format_override = 4;
}
message Rds {
option (udpa.annotations.versioning).previous_message_type =
"envoy.config.filter.network.http_connection_manager.v2.Rds";

@ -3,8 +3,10 @@ syntax = "proto3";
package envoy.extensions.filters.network.http_connection_manager.v4alpha;
import "envoy/config/accesslog/v4alpha/accesslog.proto";
import "envoy/config/core/v4alpha/base.proto";
import "envoy/config/core/v4alpha/config_source.proto";
import "envoy/config/core/v4alpha/protocol.proto";
import "envoy/config/core/v4alpha/substitution_format_string.proto";
import "envoy/config/route/v4alpha/route.proto";
import "envoy/config/route/v4alpha/scoped_route.proto";
import "envoy/config/trace/v4alpha/http_tracer.proto";
@ -507,6 +509,11 @@ message HttpConnectionManager {
// 3. Tracing decision (sampled, forced, etc) is set in 14th byte of the UUID.
RequestIDExtension request_id_extension = 36;
// The configuration to customize local reply returned by Envoy. It can customize status code,
// body text and response content type. If not specified, status code and text body are hard
// coded in Envoy, the response content type is plain text.
LocalReplyConfig local_reply_config = 38;
// Determines if the port part should be removed from host/authority header before any processing
// of request by HTTP filters or routing. The port would be removed only if it is equal to the :ref:`listener's<envoy_api_field_config.listener.v4alpha.Listener.address>`
// local port and request method is not CONNECT. This affects the upstream host header as well.
@ -516,6 +523,74 @@ message HttpConnectionManager {
bool strip_matching_host_port = 39;
}
// The configuration to customize local reply returned by Envoy.
message LocalReplyConfig {
option (udpa.annotations.versioning).previous_message_type =
"envoy.extensions.filters.network.http_connection_manager.v3.LocalReplyConfig";
// Configuration of list of mappers which allows to filter and change local response.
// The mappers will be checked by the specified order until one is matched.
repeated ResponseMapper mappers = 1;
// The configuration to form response body from the :ref:`command operators <config_access_log_command_operators>`
// and to specify response content type as one of: plain/text or application/json.
//
// Example one: plain/text body_format.
//
// .. code-block::
//
// text_format: %LOCAL_REPLY_BODY%:%RESPONSE_CODE%:path=$REQ(:path)%
//
// The following response body in `plain/text` format will be generated for a request with
// local reply body of "upstream connection error", response_code=503 and path=/foo.
//
// .. code-block::
//
// upstream connect error:503:path=/foo
//
// Example two: application/json body_format.
//
// .. code-block::
//
// json_format:
// status: %RESPONSE_CODE%
// message: %LOCAL_REPLY_BODY%
// path: $REQ(:path)%
//
// The following response body in "application/json" format would be generated for a request with
// local reply body of "upstream connection error", response_code=503 and path=/foo.
//
// .. code-block:: json
//
// {
// "status": 503,
// "message": "upstream connection error",
// "path": "/foo"
// }
//
config.core.v4alpha.SubstitutionFormatString body_format = 2;
}
// The configuration to filter and change local response.
message ResponseMapper {
option (udpa.annotations.versioning).previous_message_type =
"envoy.extensions.filters.network.http_connection_manager.v3.ResponseMapper";
// Filter to determine if this mapper should apply.
config.accesslog.v4alpha.AccessLogFilter filter = 1 [(validate.rules).message = {required: true}];
// The new response status code if specified.
google.protobuf.UInt32Value status_code = 2 [(validate.rules).uint32 = {lt: 600 gte: 200}];
// The new local reply body text if specified. It will be used in the `%LOCAL_REPLY_BODY%`
// command operator in the `body_foramt`.
config.core.v4alpha.DataSource body = 3;
// A per mapper `body_format` to override the :ref:`body_format <envoy_v3_api_field_extensions.filters.network.http_connection_manager.v3.LocalReplyConfig.body_format>`.
// It will be used when this mapper is matched.
config.core.v4alpha.SubstitutionFormatString body_format_override = 4;
}
message Rds {
option (udpa.annotations.versioning).previous_message_type =
"envoy.extensions.filters.network.http_connection_manager.v3.Rds";

Loading…
Cancel
Save