Skip to content

Commit

Permalink
fix: use http1.1 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyjames committed Feb 13, 2025
1 parent 44a62f3 commit 1894ced
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/main/java/dev/openfga/sdk/api/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ public ApiClient() {
asyncResponseInterceptor = null;
}

/**
* Create an instance of ApiClient.
* <p>
* In other contexts, note that any settings in a {@link Configuration}
* will take precedence over equivalent settings in the
* {@link HttpClient.Builder} here.
*
* @param builder Http client builder.
*/
public ApiClient(HttpClient.Builder builder) {
this.builder = builder;
this.mapper = createDefaultObjectMapper();
this.client = this.builder.build();
interceptor = null;
responseInterceptor = null;
asyncResponseInterceptor = null;
}

/**
* Create an instance of ApiClient.
* <p>
Expand Down Expand Up @@ -177,7 +195,7 @@ protected String getDefaultBaseUri() {
}

protected HttpClient.Builder createDefaultHttpClientBuilder() {
return HttpClient.newBuilder();
return HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/dev/openfga/sdk/api/client/ApiClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import java.net.http.HttpClient;

import org.checkerframework.checker.units.qual.A;
import org.junit.jupiter.api.Test;

class ApiClientTest {
Expand All @@ -35,4 +37,10 @@ public void newHttpClientWhenBuilderModified() {

assertNotEquals(client1, apiClient.getHttpClient());
}

@Test
public void httpClientShouldUseHttp1ByDefault() {
ApiClient apiClient = new ApiClient();
assertEquals(apiClient.getHttpClient().version(), HttpClient.Version.HTTP_1_1);
}
}

0 comments on commit 1894ced

Please sign in to comment.