Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add isMtls property to ApacheHttpTransport #1168

Merged
merged 27 commits into from Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e4fc0a0
feat: support keystore in transport for mtls
arithmetic1728 Oct 15, 2020
3f3d403
fix format
arithmetic1728 Oct 15, 2020
0feec05
update code
arithmetic1728 Oct 15, 2020
a71a009
add tests
arithmetic1728 Oct 16, 2020
3c10eaa
update test and doc
arithmetic1728 Oct 16, 2020
275bad0
update names
arithmetic1728 Oct 23, 2020
e21791c
create keystore from cert and key string
arithmetic1728 Oct 23, 2020
2edb134
change certAndKey from string to inputstream
arithmetic1728 Oct 26, 2020
09847d7
add mtls file
arithmetic1728 Oct 27, 2020
c4bc00d
Update google-http-client/src/main/java/com/google/api/client/http/ja…
arithmetic1728 Oct 29, 2020
a97ea3d
Update google-http-client/src/main/java/com/google/api/client/http/ja…
arithmetic1728 Oct 29, 2020
7469467
Update google-http-client/src/main/java/com/google/api/client/util/Ss…
arithmetic1728 Oct 29, 2020
a61ed1a
Update google-http-client/src/main/java/com/google/api/client/util/Ss…
arithmetic1728 Oct 29, 2020
93c3452
Update google-http-client/src/test/java/com/google/api/client/util/Se…
arithmetic1728 Oct 29, 2020
d195f65
Update google-http-client/src/main/java/com/google/api/client/util/Ss…
arithmetic1728 Oct 29, 2020
13d7d19
update the code
arithmetic1728 Oct 29, 2020
bade79a
fix name
arithmetic1728 Oct 29, 2020
a8d60ea
chore: add Beta annotation for new mtls functions
arithmetic1728 Oct 30, 2020
271c262
resolve conflict
arithmetic1728 Oct 30, 2020
eb9a90d
update Beta
arithmetic1728 Oct 30, 2020
f90ac74
add since tag
arithmetic1728 Oct 30, 2020
509c481
Merge branch 'master' of https://github.com/googleapis/google-http-ja…
arithmetic1728 Oct 31, 2020
fc72936
feat: add isMtls property to ApacheHttpTransport
arithmetic1728 Oct 29, 2020
02e53d2
update Beta annotation
arithmetic1728 Oct 31, 2020
254675e
format
arithmetic1728 Nov 1, 2020
f477636
Merge pull request #2 from arithmetic1728/apache
arithmetic1728 Nov 1, 2020
a14cac4
fix tag
arithmetic1728 Nov 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -84,6 +88,32 @@ public ApacheHttpTransport() {
*/
public ApacheHttpTransport(HttpClient httpClient) {
this.httpClient = httpClient;
this.isMtls = false;
}

/**
* {@link Beta} <br>
* Constructor that allows an alternative Apache HTTP client to be used.
*
* <p>Note that in the previous version, we overrode several settings. However, we are no longer
* able to do so.
*
* <p>If you choose to provide your own Apache HttpClient implementation, be sure that
*
* <ul>
* <li>HTTP version is set to 1.1.
* <li>Redirects are disabled (google-http-client handles redirects).
* <li>Retries are disabled (google-http-client handles retries).
* </ul>
*
* @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;
}

/**
Expand Down Expand Up @@ -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;
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down