diff --git a/google-http-client-apache-v2/src/main/java/com/google/api/client/http/apache/v2/ApacheHttpTransport.java b/google-http-client-apache-v2/src/main/java/com/google/api/client/http/apache/v2/ApacheHttpTransport.java index 02fb98a35..fcbbecf2d 100644 --- a/google-http-client-apache-v2/src/main/java/com/google/api/client/http/apache/v2/ApacheHttpTransport.java +++ b/google-http-client-apache-v2/src/main/java/com/google/api/client/http/apache/v2/ApacheHttpTransport.java @@ -16,6 +16,7 @@ import com.google.api.client.http.HttpMethods; import com.google.api.client.http.HttpTransport; +import com.google.api.client.util.Beta; import java.io.IOException; import java.net.ProxySelector; import java.util.concurrent.TimeUnit; @@ -56,13 +57,16 @@ public final class ApacheHttpTransport extends HttpTransport { /** Apache HTTP client. */ private final HttpClient httpClient; + /** If the HTTP client uses mTLS channel. */ + private final boolean isMtls; + /** * Constructor that uses {@link #newDefaultHttpClient()} for the Apache HTTP client. * * @since 1.30 */ public ApacheHttpTransport() { - this(newDefaultHttpClient()); + this(newDefaultHttpClient(), false); } /** @@ -84,6 +88,32 @@ public ApacheHttpTransport() { */ public ApacheHttpTransport(HttpClient httpClient) { this.httpClient = httpClient; + this.isMtls = false; + } + + /** + * {@link Beta}
+ * Constructor that allows an alternative Apache HTTP client to be used. + * + *

Note that in the previous version, we overrode several settings. However, we are no longer + * able to do so. + * + *

If you choose to provide your own Apache HttpClient implementation, be sure that + * + *

+ * + * @param httpClient Apache HTTP client to use + * @param isMtls If the HTTP client is mutual TLS + * @since 1.38 + */ + @Beta + public ApacheHttpTransport(HttpClient httpClient, boolean isMtls) { + this.httpClient = httpClient; + this.isMtls = isMtls; } /** @@ -192,4 +222,10 @@ public void shutdown() throws IOException { public HttpClient getHttpClient() { return httpClient; } + + /** Returns if the underlying HTTP client is mTLS. */ + @Override + public boolean isMtls() { + return isMtls; + } } diff --git a/google-http-client-apache-v2/src/test/java/com/google/api/client/http/apache/v2/ApacheHttpTransportTest.java b/google-http-client-apache-v2/src/test/java/com/google/api/client/http/apache/v2/ApacheHttpTransportTest.java index 880e7fdb6..4b9d9b8d7 100644 --- a/google-http-client-apache-v2/src/test/java/com/google/api/client/http/apache/v2/ApacheHttpTransportTest.java +++ b/google-http-client-apache-v2/src/test/java/com/google/api/client/http/apache/v2/ApacheHttpTransportTest.java @@ -15,6 +15,7 @@ package com.google.api.client.http.apache.v2; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -64,12 +65,14 @@ public class ApacheHttpTransportTest { public void testApacheHttpTransport() { ApacheHttpTransport transport = new ApacheHttpTransport(); checkHttpTransport(transport); + assertFalse(transport.isMtls()); } @Test public void testApacheHttpTransportWithParam() { - ApacheHttpTransport transport = new ApacheHttpTransport(HttpClients.custom().build()); + ApacheHttpTransport transport = new ApacheHttpTransport(HttpClients.custom().build(), true); checkHttpTransport(transport); + assertTrue(transport.isMtls()); } @Test