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

Use HTTP/1.1 unless HTTPS scheme is in URL #32

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Changes from 1 commit
Commits
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
9 changes: 8 additions & 1 deletion src/main/java/com/bisnode/opa/client/OpaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import com.bisnode.opa.client.rest.ObjectMapperFactory;
import com.bisnode.opa.client.rest.OpaRestClient;

import java.net.URI;
import java.net.http.HttpClient;
import java.util.Objects;

/**
* Opa client featuring {@link OpaDataApi}, {@link OpaQueryApi} and {@link OpaPolicyApi}
Expand Down Expand Up @@ -73,7 +75,12 @@ public Builder opaConfiguration(String url) {
}

public OpaClient build() {
HttpClient httpClient = HttpClient.newHttpClient();
Objects.requireNonNull(opaConfiguration, "build() called without opaConfiguration provided");
HttpClient httpClient = HttpClient.newBuilder()
.version("https".equals(URI.create(opaConfiguration.getUrl()).getScheme()) ?
anderseknert marked this conversation as resolved.
Show resolved Hide resolved
HttpClient.Version.HTTP_2 :
HttpClient.Version.HTTP_1_1)
.build();
OpaRestClient opaRestClient = new OpaRestClient(opaConfiguration, httpClient, ObjectMapperFactory.getInstance().create());
return new OpaClient(new OpaQueryClient(opaRestClient), new OpaDataClient(opaRestClient), new OpaPolicyClient(opaRestClient));
}
Expand Down