use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter in project grpc-java by grpc.
the class ClientXdsClient method parseHttpConnectionManager.
@VisibleForTesting
static io.grpc.xds.HttpConnectionManager parseHttpConnectionManager(HttpConnectionManager proto, Set<String> rdsResources, FilterRegistry filterRegistry, boolean parseHttpFilter, boolean isForClient) throws ResourceInvalidException {
if (enableRbac && proto.getXffNumTrustedHops() != 0) {
throw new ResourceInvalidException("HttpConnectionManager with xff_num_trusted_hops unsupported");
}
if (enableRbac && !proto.getOriginalIpDetectionExtensionsList().isEmpty()) {
throw new ResourceInvalidException("HttpConnectionManager with " + "original_ip_detection_extensions unsupported");
}
// Obtain max_stream_duration from Http Protocol Options.
long maxStreamDuration = 0;
if (proto.hasCommonHttpProtocolOptions()) {
HttpProtocolOptions options = proto.getCommonHttpProtocolOptions();
if (options.hasMaxStreamDuration()) {
maxStreamDuration = Durations.toNanos(options.getMaxStreamDuration());
}
}
// Parse http filters.
List<NamedFilterConfig> filterConfigs = null;
if (parseHttpFilter) {
if (proto.getHttpFiltersList().isEmpty()) {
throw new ResourceInvalidException("Missing HttpFilter in HttpConnectionManager.");
}
filterConfigs = new ArrayList<>();
Set<String> names = new HashSet<>();
for (int i = 0; i < proto.getHttpFiltersCount(); i++) {
io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter httpFilter = proto.getHttpFiltersList().get(i);
String filterName = httpFilter.getName();
if (!names.add(filterName)) {
throw new ResourceInvalidException("HttpConnectionManager contains duplicate HttpFilter: " + filterName);
}
StructOrError<FilterConfig> filterConfig = parseHttpFilter(httpFilter, filterRegistry, isForClient);
if ((i == proto.getHttpFiltersCount() - 1) && (filterConfig == null || !isTerminalFilter(filterConfig.struct))) {
throw new ResourceInvalidException("The last HttpFilter must be a terminal filter: " + filterName);
}
if (filterConfig == null) {
continue;
}
if (filterConfig.getErrorDetail() != null) {
throw new ResourceInvalidException("HttpConnectionManager contains invalid HttpFilter: " + filterConfig.getErrorDetail());
}
if ((i < proto.getHttpFiltersCount() - 1) && isTerminalFilter(filterConfig.getStruct())) {
throw new ResourceInvalidException("A terminal HttpFilter must be the last filter: " + filterName);
}
filterConfigs.add(new NamedFilterConfig(filterName, filterConfig.struct));
}
}
// Parse inlined RouteConfiguration or RDS.
if (proto.hasRouteConfig()) {
List<VirtualHost> virtualHosts = extractVirtualHosts(proto.getRouteConfig(), filterRegistry, parseHttpFilter);
return io.grpc.xds.HttpConnectionManager.forVirtualHosts(maxStreamDuration, virtualHosts, filterConfigs);
}
if (proto.hasRds()) {
Rds rds = proto.getRds();
if (!rds.hasConfigSource()) {
throw new ResourceInvalidException("HttpConnectionManager contains invalid RDS: missing config_source");
}
if (!rds.getConfigSource().hasAds() && !rds.getConfigSource().hasSelf()) {
throw new ResourceInvalidException("HttpConnectionManager contains invalid RDS: must specify ADS or self ConfigSource");
}
// Collect the RDS resource referenced by this HttpConnectionManager.
rdsResources.add(rds.getRouteConfigName());
return io.grpc.xds.HttpConnectionManager.forRdsName(maxStreamDuration, rds.getRouteConfigName(), filterConfigs);
}
throw new ResourceInvalidException("HttpConnectionManager neither has inlined route_config nor RDS");
}
use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter in project grpc-java by grpc.
the class FakeControlPlaneXdsIntegrationTest method clientListener.
private static Listener clientListener(String name) {
HttpFilter httpFilter = HttpFilter.newBuilder().setName("terminal-filter").setTypedConfig(Any.pack(Router.newBuilder().build())).setIsOptional(true).build();
ApiListener apiListener = ApiListener.newBuilder().setApiListener(Any.pack(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager.newBuilder().setRds(Rds.newBuilder().setRouteConfigName(rdsName).setConfigSource(ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance()))).addAllHttpFilters(Collections.singletonList(httpFilter)).build(), HTTP_CONNECTION_MANAGER_TYPE_URL)).build();
Listener listener = Listener.newBuilder().setName(name).setApiListener(apiListener).build();
return listener;
}
use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter in project grpc-java by grpc.
the class ClientXdsClientDataTest method parseHttpConnectionManager_lastNotTerminal.
@Test
public void parseHttpConnectionManager_lastNotTerminal() throws ResourceInvalidException {
filterRegistry.register(FaultFilter.INSTANCE);
HttpConnectionManager hcm = HttpConnectionManager.newBuilder().addHttpFilters(HttpFilter.newBuilder().setName("envoy.filter.foo").setIsOptional(true)).addHttpFilters(HttpFilter.newBuilder().setName("envoy.filter.bar").setIsOptional(true).setTypedConfig(Any.pack(HTTPFault.newBuilder().build()))).build();
thrown.expect(ResourceInvalidException.class);
thrown.expectMessage("The last HttpFilter must be a terminal filter: envoy.filter.bar");
ClientXdsClient.parseHttpConnectionManager(hcm, new HashSet<String>(), filterRegistry, true, /* parseHttpFilter */
true);
}
use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter in project grpc-java by grpc.
the class ClientXdsClientDataTest method parseHttpConnectionManager_emptyFilters.
@Test
public void parseHttpConnectionManager_emptyFilters() throws ResourceInvalidException {
HttpConnectionManager hcm = HttpConnectionManager.newBuilder().build();
thrown.expect(ResourceInvalidException.class);
thrown.expectMessage("Missing HttpFilter in HttpConnectionManager.");
ClientXdsClient.parseHttpConnectionManager(hcm, new HashSet<String>(), filterRegistry, true, /* parseHttpFilter */
true);
}
use of io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter in project grpc-java by grpc.
the class ClientXdsClientDataTest method parseHttpFilter_typedStructMigration.
@Test
public void parseHttpFilter_typedStructMigration() {
filterRegistry.register(new TestFilter());
Struct rawStruct = Struct.newBuilder().putFields("name", Value.newBuilder().setStringValue("default").build()).build();
HttpFilter httpFilter = HttpFilter.newBuilder().setIsOptional(true).setTypedConfig(Any.pack(com.github.udpa.udpa.type.v1.TypedStruct.newBuilder().setTypeUrl("test-url").setValue(rawStruct).build())).build();
FilterConfig config = ClientXdsClient.parseHttpFilter(httpFilter, filterRegistry, true).getStruct();
assertThat(((SimpleFilterConfig) config).getConfig()).isEqualTo(rawStruct);
HttpFilter httpFilterNewTypeStruct = HttpFilter.newBuilder().setIsOptional(true).setTypedConfig(Any.pack(TypedStruct.newBuilder().setTypeUrl("test-url").setValue(rawStruct).build())).build();
config = ClientXdsClient.parseHttpFilter(httpFilterNewTypeStruct, filterRegistry, true).getStruct();
assertThat(((SimpleFilterConfig) config).getConfig()).isEqualTo(rawStruct);
}
Aggregations