-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix for #7801 - webclient proxy cannot be set using configuration. * Fix for #7802 - webclient protocol configuration for HTTP/2 did not work.
- Loading branch information
1 parent
0b9c995
commit b1963dd
Showing
7 changed files
with
238 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
webclient/http2/src/main/java/io/helidon/webclient/http2/Http2ProtocolConfigProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.webclient.http2; | ||
|
||
import io.helidon.common.config.Config; | ||
import io.helidon.webclient.spi.ProtocolConfigProvider; | ||
|
||
/** | ||
* Implementation of protocol config provider. | ||
*/ | ||
public class Http2ProtocolConfigProvider implements ProtocolConfigProvider<Http2ClientProtocolConfig> { | ||
/** | ||
* Required to be used by {@link java.util.ServiceLoader}. | ||
* @deprecated do not use directly, use Http1ClientProtocol | ||
*/ | ||
public Http2ProtocolConfigProvider() { | ||
} | ||
|
||
@Override | ||
public String configKey() { | ||
return Http2ProtocolProvider.CONFIG_KEY; | ||
} | ||
|
||
@Override | ||
public Http2ClientProtocolConfig create(Config config, String name) { | ||
return Http2ClientProtocolConfig.builder() | ||
.config(config) | ||
.name(name) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
webclient/tests/http2/src/test/java/io/helidon/webclient/tests/http2/ProtocolConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.webclient.tests.http2; | ||
|
||
import java.util.List; | ||
|
||
import io.helidon.config.Config; | ||
import io.helidon.config.ConfigSources; | ||
import io.helidon.webclient.api.WebClient; | ||
import io.helidon.webclient.http1.Http1ClientProtocolConfig; | ||
import io.helidon.webclient.http2.Http2ClientProtocolConfig; | ||
import io.helidon.webclient.spi.ProtocolConfig; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize; | ||
|
||
class ProtocolConfigTest { | ||
@Test | ||
void testProtocolConfigWorks() { | ||
Config config = Config.just(ConfigSources.classpath("protocol-config-test.yaml")); | ||
// reproducer for #7802 - h2 protocol not recognized | ||
WebClient client = WebClient.builder() | ||
.config(config.get("client")) | ||
.build(); | ||
assertThat(client, notNullValue()); | ||
|
||
List<ProtocolConfig> protocolConfigs = client.prototype() | ||
.protocolConfigs(); | ||
|
||
assertThat(protocolConfigs, hasSize(2)); | ||
|
||
/* | ||
Should be ordered by weight, first HTTP/2 | ||
*/ | ||
ProtocolConfig http2Config = protocolConfigs.get(0); | ||
assertThat(http2Config, instanceOf(Http2ClientProtocolConfig.class)); | ||
|
||
ProtocolConfig http1Config = protocolConfigs.get(1); | ||
assertThat(http1Config, instanceOf(Http1ClientProtocolConfig.class)); | ||
|
||
Http2ClientProtocolConfig http2cast = (Http2ClientProtocolConfig) http2Config; | ||
assertThat(http2cast.priorKnowledge(), is(true)); | ||
|
||
Http1ClientProtocolConfig http1cast = (Http1ClientProtocolConfig) http1Config; | ||
assertThat(http1cast.maxHeaderSize(), is(20000)); | ||
assertThat(http1cast.validateRequestHeaders(), is(false)); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
webclient/tests/http2/src/test/resources/protocol-config-test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Copyright (c) 2023 Oracle and/or its affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
client: | ||
protocol-configs: | ||
http_1_1: | ||
max-header-size: 20000 | ||
validate-request-headers: false | ||
h2: | ||
prior-knowledge: true |
66 changes: 66 additions & 0 deletions
66
webclient/tests/webclient/src/test/java/io/helidon/webclient/tests/ProxySetupTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.webclient.tests; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
import io.helidon.config.Config; | ||
import io.helidon.config.ConfigSources; | ||
import io.helidon.webclient.api.Proxy; | ||
import io.helidon.webclient.api.WebClient; | ||
import io.helidon.webclient.api.WebClientConfig; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static io.helidon.common.testing.junit5.OptionalMatcher.optionalValue; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class ProxySetupTest { | ||
private static final Config CONFIG = Config.just(ConfigSources.classpath("proxy-setup-test.yaml")); | ||
|
||
@Test | ||
void testNoProxy() { | ||
WebClient webClient = WebClient.create(WebClientConfig.create(CONFIG.get("no-proxy"))); | ||
Proxy proxy = webClient.prototype().proxy(); | ||
|
||
assertThat(proxy.type(), is(Proxy.ProxyType.NONE)); | ||
} | ||
|
||
@Test | ||
void testSystemProxy() { | ||
WebClient webClient = WebClient.create(WebClientConfig.create(CONFIG.get("system-proxy"))); | ||
Proxy proxy = webClient.prototype().proxy(); | ||
|
||
assertThat(proxy.type(), is(Proxy.ProxyType.SYSTEM)); | ||
} | ||
|
||
@Test | ||
void testHttpProxy() { | ||
WebClient webClient = WebClient.create(WebClientConfig.create(CONFIG.get("http-proxy"))); | ||
Proxy proxy = webClient.prototype().proxy(); | ||
|
||
assertThat(proxy.type(), is(Proxy.ProxyType.HTTP)); | ||
assertThat(proxy.host(), is("proxy.host.example")); | ||
assertThat(proxy.port(), is(9999)); | ||
assertThat(proxy.username(), optionalValue(is("user"))); | ||
assertThat(proxy.password(), optionalValue(is("password".toCharArray()))); | ||
assertThat(proxy.isNoHosts(new InetSocketAddress("www.helidon.io", 80)), is(true)); | ||
assertThat(proxy.isNoHosts(new InetSocketAddress("start.helidon.io", 80)), is(true)); | ||
assertThat(proxy.isNoHosts(new InetSocketAddress("www.oracle.com", 80)), is(false)); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
webclient/tests/webclient/src/test/resources/proxy-setup-test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# Copyright (c) 2023 Oracle and/or its affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
no-proxy: | ||
proxy: | ||
type: "NONE" | ||
|
||
system-proxy: | ||
proxy: | ||
type: "SYSTEM" | ||
|
||
http-proxy: | ||
proxy: | ||
type: "HTTP" | ||
host: "proxy.host.example" | ||
port: 9999 | ||
username: "user" | ||
password: "password" | ||
no-proxy: ".helidon.io" |