Repository: istio/istio
File: pilot/pkg/xds/filters/filters.go (Go)

Code before:
					},
					ForwardingNamespaces: &extproc.MetadataOptions_MetadataNamespaces{
						Untyped: []string{constants.EnvoySubsetNamespace},
					},
				},
			}),
		},
	}
	Alpn = &hcm.HttpFilter{
		Name: AlpnFilterName,
		ConfigType: &hcm.HttpFilter_TypedConfig{
			TypedConfig: protoconv.MessageToAny(&alpn.FilterConfig{
				AlpnOverride: []*alpn.FilterConfig_AlpnOverride{
					{
						UpstreamProtocol: alpn.FilterConfig_HTTP10,
						AlpnOverride:     mtlsHTTP10ALPN,
					},
					{
						UpstreamProtocol: alpn.FilterConfig_HTTP11,
						AlpnOverride:     mtlsHTTP11ALPN,
					},
					{
						UpstreamProtocol: alpn.FilterConfig_HTTP2,
						AlpnOverride:     mtlsHTTP2ALPN,
					},
				},
			}),
		},
	}

	// This filter is used to capture value of istio-l7-policies-applied header from the HBONE connect request in the filter state.
	// This header in multi-network ambient mode indicates whether L7 policies have been applied already to the
	// request. For example, if the request went from ztunnel to waypoint and then to E/W gateway, then waypoint would have already
	// applied L7 policies to the request, so E/W gateway should not send the request to waypoint to avoid applying the L7 policies
	// again. On the other hand, if ztunnel directly sent the request to the E/W gateway, then the request still needs L7 policies
	// to be applied and so has to be routed to the waypoint if the service has one.
	RequestSourceFilter = &hcm.HttpFilter{
		Name: "request_source",
		ConfigType: &hcm.HttpFilter_TypedConfig{
			TypedConfig: protoconv.MessageToAny(&sfs.Config{
				OnRequestHeaders: []*sfsvalue.FilterStateValue{
					{
						Key: &sfsvalue.FilterStateValue_ObjectKey{
							ObjectKey: RequestSourceFilterStateKey,
						},
						Value: &sfsvalue.FilterStateValue_FormatString{
							FormatString: &core.SubstitutionFormatString{
								Format: &core.SubstitutionFormatString_TextFormatSource{
									TextFormatSource: &core.DataSource{
										Specifier: &core.DataSource_InlineString{
											InlineString: "%REQ(x-istio-source)%",

Review comment (suggestion):
moving to a static function is definitely better, but I think we should probably avoid deleting these and the func should just be a few lines that decides which package-level var to return based on the env

It makes it much easier to see what filter is actually getting returned if we have each mode "rendered" into one of these pseudo-constants

Code after:
					},
				},
			}),
		},
	}
	Alpn = &hcm.HttpFilter{
		Name: AlpnFilterName,
		ConfigType: &hcm.HttpFilter_TypedConfig{
			TypedConfig: protoconv.MessageToAny(&alpn.FilterConfig{
				AlpnOverride: []*alpn.FilterConfig_AlpnOverride{
					{
						UpstreamProtocol: alpn.FilterConfig_HTTP10,
						AlpnOverride:     mtlsHTTP10ALPN,
					},
					{
						UpstreamProtocol: alpn.FilterConfig_HTTP11,
						AlpnOverride:     mtlsHTTP11ALPN,
					},
					{
						UpstreamProtocol: alpn.FilterConfig_HTTP2,
						AlpnOverride:     mtlsHTTP2ALPN,
					},
				},
			}),
		},
	}

	// This filter is used to capture value of istio-l7-policies-applied header from the HBONE connect request in the filter state.
	// This header in multi-network ambient mode indicates whether L7 policies have been applied already to the
	// request. For example, if the request went from ztunnel to waypoint and then to E/W gateway, then waypoint would have already
	// applied L7 policies to the request, so E/W gateway should not send the request to waypoint to avoid applying the L7 policies
	// again. On the other hand, if ztunnel directly sent the request to the E/W gateway, then the request still needs L7 policies
	// to be applied and so has to be routed to the waypoint if the service has one.
	RequestSourceFilter = &hcm.HttpFilter{
		Name: "request_source",
		ConfigType: &hcm.HttpFilter_TypedConfig{
			TypedConfig: protoconv.MessageToAny(&sfs.Config{
				OnRequestHeaders: []*sfsvalue.FilterStateValue{
					{
						Key: &sfsvalue.FilterStateValue_ObjectKey{
							ObjectKey: RequestSourceFilterStateKey,
						},
						Value: &sfsvalue.FilterStateValue_FormatString{
							FormatString: &core.SubstitutionFormatString{
								Format: &core.SubstitutionFormatString_TextFormatSource{
									TextFormatSource: &core.DataSource{
										Specifier: &core.DataSource_InlineString{
											InlineString: "%REQ(x-istio-source)%",
										},
									},
								},