<commit_before>// NOLINT(namespace-envoy)
#include "library/common/config/internal.h"
#include "library/common/config/templates.h"

const int custom_cluster_indent = 2;
const int custom_listener_indent = 2;
const int custom_filter_indent = 8;
const int custom_route_indent = 14;

const int fake_remote_response_indent = 14;
const char* fake_remote_cluster_insert = "  - *fake_remote_cluster\n";
const char* fake_remote_listener_insert = "  - *fake_remote_listener\n";
const char* fake_remote_route_insert = "              - *fake_remote_route\n";

const char* platform_filter_template = R"(
        - name: envoy.filters.http.platform_bridge
          typed_config:
            "@type": type.googleapis.com/envoymobile.extensions.filters.http.platform_bridge.PlatformBridge
            platform_filter_name: {{ platform_filter_name }}
)";

const char* native_filter_template = R"(
        - name: {{ native_filter_name }}
          typed_config: {{ native_filter_typed_config }}
)";

const char* route_cache_reset_filter_insert = R"(
        - name: envoy.filters.http.route_cache_reset
          typed_config:
            "@type": type.googleapis.com/envoymobile.extensions.filters.http.route_cache_reset.RouteCacheReset
)";

const std::string config_header = R"(
!ignore default_defs:
- &connect_timeout 30s
- &dns_refresh_rate 60s
- &dns_fail_base_interval 2s
- &dns_fail_max_interval 10s
- &metadata {}
- &stats_domain 127.0.0.1
- &stats_flush_interval 60s
- &stats_sinks []
- &statsd_host 127.0.0.1
- &statsd_port 8125
- &stream_idle_timeout 15s
- &virtual_clusters []

!ignore stats_defs:
  base_metrics_service: &base_metrics_service
    name: envoy.metrics_service
    typed_config:
      "@type": type.googleapis.com/envoy.config.metrics.v3.MetricsServiceConfig
      transport_api_version: V3
      report_counters_as_deltas: true
      emit_tags_as_labels: true
      grpc_service:
        envoy_grpc:
          cluster_name: stats
  base_statsd: &base_statsd
    name: envoy.stat_sinks.statsd
    typed_config:
      "@type": type.googleapis.com/envoy.config.metrics.v3.StatsdSink
      address:
        socket_address: { address: *statsd_host, port_value: *statsd_port }

!ignore tls_socket_defs: &base_tls_socket
  name: envoy.transport_sockets.tls
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
    common_tls_context:
      validation_context:
        trusted_ca:
          inline_string: |
)"
#include "certificates.inc"
    ;

const char* config_template = R"(
!ignore custom_listener_defs:
  fake_remote_listener: &fake_remote_listener
    name: fake_remote_listener
    address:
      socket_address: { protocol: TCP, address: 127.0.0.1, port_value: 10101 }
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          stat_prefix: remote_hcm
          route_config:
            name: remote_route
            virtual_hosts:
            - name: remote_service
              domains: ["*"]
              routes:
#{fake_remote_responses}
              - match: { prefix: "/" }
                direct_response: { status: 404, body: { inline_string: "not found" } }
          http_filters:
          - name: envoy.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

!ignore custom_cluster_defs:
  stats_cluster: &stats_cluster
    name: stats
    type: LOGICAL_DNS
    connect_timeout: *connect_timeout
    dns_refresh_rate: *dns_refresh_rate
    http2_protocol_options: {}
    lb_policy: ROUND_ROBIN
    load_assignment:
      cluster_name: stats
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address: { address: *stats_domain, port_value: 443 }
    transport_socket: *base_tls_socket
  fake_remote_cluster: &fake_remote_cluster
    name: fake_remote
    type: LOGICAL_DNS
    connect_timeout: *connect_timeout
    lb_policy: ROUND_ROBIN
    load_assignment:
      cluster_name: fake_remote
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address: { address: 127.0.0.1, port_value: 10101 }

static_resources:
  listeners:
#{custom_listeners}
  - name: base_api_listener
    address:
      socket_address:
        protocol: TCP
        address: 0.0.0.0
        port_value: 10000
    per_connection_buffer_limit_bytes: 10485760 # 10MB
    api_listener:
      api_listener:
        "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
        stat_prefix: hcm
        stream_idle_timeout: *stream_idle_timeout
        route_config:
          name: api_router
          virtual_hosts:
            - name: api
              include_attempt_count_in_response: true
              virtual_clusters: *virtual_clusters
              domains: ["*"]
              routes:
#{custom_routes}
              - match: { prefix: "/" }
                route:
                  cluster_header: x-envoy-mobile-cluster
                  timeout: 0s
                  retry_policy:
                    retry_back_off:
                      base_interval: 0.25s
                      max_interval: 60s
        http_filters:
#{custom_filters}
        - name: envoy.filters.http.local_error
          typed_config:
            "@type": type.googleapis.com/envoymobile.extensions.filters.http.local_error.LocalError<commit_msg>headers: not overwriting the server header (#1541)<commit_after>// NOLINT(namespace-envoy)
#include "library/common/config/internal.h"
#include "library/common/config/templates.h"

const int custom_cluster_indent = 2;
const int custom_listener_indent = 2;
const int custom_filter_indent = 8;
const int custom_route_indent = 14;

const int fake_remote_response_indent = 14;
const char* fake_remote_cluster_insert = "  - *fake_remote_cluster\n";
const char* fake_remote_listener_insert = "  - *fake_remote_listener\n";
const char* fake_remote_route_insert = "              - *fake_remote_route\n";

const char* platform_filter_template = R"(
        - name: envoy.filters.http.platform_bridge
          typed_config:
            "@type": type.googleapis.com/envoymobile.extensions.filters.http.platform_bridge.PlatformBridge
            platform_filter_name: {{ platform_filter_name }}
)";

const char* native_filter_template = R"(
        - name: {{ native_filter_name }}
          typed_config: {{ native_filter_typed_config }}
)";

const char* route_cache_reset_filter_insert = R"(
        - name: envoy.filters.http.route_cache_reset
          typed_config:
            "@type": type.googleapis.com/envoymobile.extensions.filters.http.route_cache_reset.RouteCacheReset
)";

const std::string config_header = R"(
!ignore default_defs:
- &connect_timeout 30s
- &dns_refresh_rate 60s
- &dns_fail_base_interval 2s
- &dns_fail_max_interval 10s
- &metadata {}
- &stats_domain 127.0.0.1
- &stats_flush_interval 60s
- &stats_sinks []
- &statsd_host 127.0.0.1
- &statsd_port 8125
- &stream_idle_timeout 15s
- &virtual_clusters []

!ignore stats_defs:
  base_metrics_service: &base_metrics_service
    name: envoy.metrics_service
    typed_config:
      "@type": type.googleapis.com/envoy.config.metrics.v3.MetricsServiceConfig
      transport_api_version: V3
      report_counters_as_deltas: true
      emit_tags_as_labels: true
      grpc_service:
        envoy_grpc:
          cluster_name: stats
  base_statsd: &base_statsd
    name: envoy.stat_sinks.statsd
    typed_config:
      "@type": type.googleapis.com/envoy.config.metrics.v3.StatsdSink
      address:
        socket_address: { address: *statsd_host, port_value: *statsd_port }

!ignore tls_socket_defs: &base_tls_socket
  name: envoy.transport_sockets.tls
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
    common_tls_context:
      validation_context:
        trusted_ca:
          inline_string: |
)"
#include "certificates.inc"
    ;

const char* config_template = R"(
!ignore custom_listener_defs:
  fake_remote_listener: &fake_remote_listener
    name: fake_remote_listener
    address:
      socket_address: { protocol: TCP, address: 127.0.0.1, port_value: 10101 }
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          stat_prefix: remote_hcm
          route_config:
            name: remote_route
            virtual_hosts:
            - name: remote_service
              domains: ["*"]
              routes:
#{fake_remote_responses}
              - match: { prefix: "/" }
                direct_response: { status: 404, body: { inline_string: "not found" } }
          http_filters:
          - name: envoy.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

!ignore custom_cluster_defs:
  stats_cluster: &stats_cluster
    name: stats
    type: LOGICAL_DNS
    connect_timeout: *connect_timeout
    dns_refresh_rate: *dns_refresh_rate
    http2_protocol_options: {}
    lb_policy: ROUND_ROBIN
    load_assignment:
      cluster_name: stats
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address: { address: *stats_domain, port_value: 443 }
    transport_socket: *base_tls_socket
  fake_remote_cluster: &fake_remote_cluster
    name: fake_remote
    type: LOGICAL_DNS
    connect_timeout: *connect_timeout
    lb_policy: ROUND_ROBIN
    load_assignment:
      cluster_name: fake_remote
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address: { address: 127.0.0.1, port_value: 10101 }

static_resources:
  listeners:
#{custom_listeners}
  - name: base_api_listener
    address:
      socket_address:
        protocol: TCP
        address: 0.0.0.0
        port_value: 10000
    per_connection_buffer_limit_bytes: 10485760 # 10MB
    api_listener:
      api_listener:
        "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
        stat_prefix: hcm
        server_header_transformation: PASS_THROUGH
        stream_idle_timeout: *stream_idle_timeout
        route_config:
          name: api_router
          virtual_hosts:
            - name: api
              include_attempt_count_in_response: true
              virtual_clusters: *virtual_clusters
              domains: ["*"]
              routes:
#{custom_routes}
              - match: { prefix: "/" }
                route:
                  cluster_header: x-envoy-mobile-cluster
                  timeout: 0s
                  retry_policy:
                    retry_back_off:
                      base_interval: 0.25s
                      max_interval: 60s
        http_filters:
#{custom_filters}
        - name: envoy.filters.http.local_error
          typed_config:
            "@type": type.googleapis.com/envoymobile.extensions.filters.http.local_error.LocalError
{'fraction_non_alphanumeric': 0.08863113157428723, 'fraction_numerical': 0.017177262263148575, 'mean_word_length': 2.7215815485996706, 'pattern_counts': {'":': 18, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 10, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1055528', 'n_tokens_mistral': 3637, 'n_tokens_neox': 3517, 'n_words': 603}