1 /* 2 * Copyright 2021 The gRPC Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package io.grpc.xds; 18 19 import static com.google.common.base.Preconditions.checkNotNull; 20 21 import com.google.auto.value.AutoValue; 22 import com.google.common.collect.ImmutableList; 23 import io.grpc.xds.Filter.NamedFilterConfig; 24 import java.util.List; 25 import javax.annotation.Nullable; 26 27 /** 28 * HttpConnectionManager is a network filter for proxying HTTP requests. 29 */ 30 @AutoValue 31 abstract class HttpConnectionManager { 32 // Total number of nanoseconds to keep alive an HTTP request/response stream. httpMaxStreamDurationNano()33 abstract long httpMaxStreamDurationNano(); 34 35 // Name of the route configuration to be used for RDS resource discovery. 36 @Nullable rdsName()37 abstract String rdsName(); 38 39 // List of virtual hosts that make up the route table. 40 @Nullable virtualHosts()41 abstract ImmutableList<VirtualHost> virtualHosts(); 42 43 // List of http filter configs. Null if HttpFilter support is not enabled. 44 @Nullable httpFilterConfigs()45 abstract ImmutableList<NamedFilterConfig> httpFilterConfigs(); 46 forRdsName(long httpMaxStreamDurationNano, String rdsName, @Nullable List<NamedFilterConfig> httpFilterConfigs)47 static HttpConnectionManager forRdsName(long httpMaxStreamDurationNano, String rdsName, 48 @Nullable List<NamedFilterConfig> httpFilterConfigs) { 49 checkNotNull(rdsName, "rdsName"); 50 return create(httpMaxStreamDurationNano, rdsName, null, httpFilterConfigs); 51 } 52 forVirtualHosts(long httpMaxStreamDurationNano, List<VirtualHost> virtualHosts, @Nullable List<NamedFilterConfig> httpFilterConfigs)53 static HttpConnectionManager forVirtualHosts(long httpMaxStreamDurationNano, 54 List<VirtualHost> virtualHosts, @Nullable List<NamedFilterConfig> httpFilterConfigs) { 55 checkNotNull(virtualHosts, "virtualHosts"); 56 return create(httpMaxStreamDurationNano, null, virtualHosts, 57 httpFilterConfigs); 58 } 59 create(long httpMaxStreamDurationNano, @Nullable String rdsName, @Nullable List<VirtualHost> virtualHosts, @Nullable List<NamedFilterConfig> httpFilterConfigs)60 private static HttpConnectionManager create(long httpMaxStreamDurationNano, 61 @Nullable String rdsName, @Nullable List<VirtualHost> virtualHosts, 62 @Nullable List<NamedFilterConfig> httpFilterConfigs) { 63 return new AutoValue_HttpConnectionManager( 64 httpMaxStreamDurationNano, rdsName, 65 virtualHosts == null ? null : ImmutableList.copyOf(virtualHosts), 66 httpFilterConfigs == null ? null : ImmutableList.copyOf(httpFilterConfigs)); 67 } 68 } 69