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

fix: set default HTTP protocol to HTTP 1.1 #241

Merged
merged 2 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The `shift()` function renamed to `timeShift()`.
### Bug Fixes
1. [#227](https://github.com/influxdata/influxdb-client-java/pull/227): Connection URL with custom base path
1. [#236](https://github.com/influxdata/influxdb-client-java/pull/236): Rename `shift()` to `timeShift()` [FluxDSL]
1. [#241](https://github.com/influxdata/influxdb-client-java/pull/241): Set default HTTP protocol to HTTP 1.1

### Dependencies
1. [#227](https://github.com/influxdata/influxdb-client-java/pull/227): Update dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package com.influxdb.client.flux;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand All @@ -35,6 +36,7 @@

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;

/**
* FluxConnectionOptions are used to configure queries to the Flux.
Expand Down Expand Up @@ -121,7 +123,8 @@ public Map<String, String> getParameters() {
public static class Builder {

private String url;
private OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();
private OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder()
.protocols(Collections.singletonList(Protocol.HTTP_1_1));
private Map<String, String> parameters = new HashMap<>();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
*/
package com.influxdb.client.flux;

import java.util.List;

import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
Expand Down Expand Up @@ -65,4 +68,16 @@ void okHttpClientValue() {

Assertions.assertThat(fluxConnectionOptions.getOkHttpClient()).isEqualTo(okHttpClient);
}

@Test
void protocolVersion() {

FluxConnectionOptions options = FluxConnectionOptions.builder()
.url("http://localhost:8093")
.build();

List<Protocol> protocols = options.getOkHttpClient().build().protocols();
Assertions.assertThat(protocols).hasSize(1);
Assertions.assertThat(protocols).contains(Protocol.HTTP_1_1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.InputStream;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -39,6 +40,7 @@

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;

/**
* InfluxDBClientOptions are used to configure theInfluxDB 2.0 connections.
Expand Down Expand Up @@ -445,7 +447,8 @@ public InfluxDBClientOptions build() {
}

if (okHttpClient == null) {
okHttpClient = new OkHttpClient.Builder();
okHttpClient = new OkHttpClient.Builder()
.protocols(Collections.singletonList(Protocol.HTTP_1_1));
}

if (logLevel == null) {
Expand Down Expand Up @@ -477,7 +480,8 @@ private InfluxDBClientOptions.Builder configure(@Nonnull final String url,
logLevel(Enum.valueOf(LogLevel.class, logLevel));
}

okHttpClient = new OkHttpClient.Builder();
okHttpClient = new OkHttpClient.Builder()
.protocols(Collections.singletonList(Protocol.HTTP_1_1));
if (readTimeout != null) {
okHttpClient.readTimeout(toDuration(readTimeout));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
*/
package com.influxdb.client;

import java.util.List;

import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
Expand Down Expand Up @@ -87,4 +90,17 @@ void authorizationSession() {

Assertions.assertThat(options.getAuthScheme()).isEqualTo(InfluxDBClientOptions.AuthScheme.SESSION);
}

@Test
void protocolVersion() {

InfluxDBClientOptions options = InfluxDBClientOptions.builder()
.url("http://localhost:9999")
.authenticateToken("xyz".toCharArray())
.build();

List<Protocol> protocols = options.getOkHttpClient().build().protocols();
Assertions.assertThat(protocols).hasSize(1);
Assertions.assertThat(protocols).contains(Protocol.HTTP_1_1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
*/
package com.influxdb.spring.influx;

import java.util.Collections;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.InfluxDBClientOptions;

import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand Down Expand Up @@ -64,6 +67,7 @@ public InfluxDBClient influxDBClient() {
OkHttpClient.Builder okHttpBuilder;
if (builderProvider == null) {
okHttpBuilder = new OkHttpClient.Builder()
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
.readTimeout(properties.getReadTimeout())
.writeTimeout(properties.getWriteTimeout())
.connectTimeout(properties.getConnectTimeout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
*/
package com.influxdb.spring.influx;

import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nonnull;

import com.influxdb.client.InfluxDBClient;

import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
Expand Down Expand Up @@ -96,11 +100,27 @@ public void influxDBClientWithReadTimeout() {
});
}

@Test
public void protocolVersion() {
this.contextRunner.withPropertyValues("spring.influx2.url=http://localhost:8086/", "spring.influx2.token:token")
.run((context) -> {
List<Protocol> protocols = getOkHttpClient(context).protocols();
Assertions.assertThat(protocols).hasSize(1);
Assertions.assertThat(protocols).contains(Protocol.HTTP_1_1);
});
}

private int getReadTimeoutProperty(AssertableApplicationContext context) {
OkHttpClient callFactory = getOkHttpClient(context);
return callFactory.readTimeoutMillis();
}

@Nonnull
private OkHttpClient getOkHttpClient(final AssertableApplicationContext context) {
InfluxDBClient influxDB = context.getBean(InfluxDBClient.class);
Retrofit retrofit = (Retrofit) ReflectionTestUtils.getField(influxDB, "retrofit");
OkHttpClient callFactory = (OkHttpClient) retrofit.callFactory();
return callFactory.readTimeoutMillis();
return callFactory;
}

@Configuration
Expand Down