Skip to content

Commit ceba096

Browse files
authored
Set HTTP as default proxy type when specified via config in WebClient (helidon-io#3551)
* Set HTTP as default proxy type when specified via config and type isn't provided. Fix a few type related warnings. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com> * Fixed typo in comment. Signed-off-by: Santiago Pericasgeertsen <santiago.pericasgeertsen@oracle.com>
1 parent 0975d73 commit ceba096

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

webclient/webclient/src/main/java/io/helidon/webclient/Proxy.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ Function<URI, Boolean> noProxyPredicate() {
147147
return noProxy;
148148
}
149149

150+
/**
151+
* Get proxy type. For testing purposes.
152+
*
153+
* @return the proxy type
154+
*/
155+
ProxyType type() {
156+
return type;
157+
}
158+
150159
static Function<URI, Boolean> prepareNoProxy(Set<String> noProxyHosts) {
151160
if (noProxyHosts.isEmpty()) {
152161
// if no exceptions, then simple
@@ -473,7 +482,7 @@ public Proxy build() {
473482
public Builder config(Config config) {
474483
config.get("use-system-selector").asBoolean().ifPresent(this::useSystemSelector);
475484
if (this.type != ProxyType.SYSTEM) {
476-
config.get("type").asString().map(ProxyType::valueOf).ifPresent(this::type);
485+
config.get("type").asString().map(ProxyType::valueOf).ifPresentOrElse(this::type, () -> type(ProxyType.HTTP));
477486
config.get("host").asString().ifPresent(this::host);
478487
config.get("port").asInt().ifPresent(this::port);
479488
config.get("username").asString().ifPresent(this::username);

webclient/webclient/src/main/java/io/helidon/webclient/WebClientConfiguration.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ class WebClientConfiguration {
116116
*
117117
* @return a new builder instance
118118
*/
119-
static Builder builder() {
120-
return new Builder();
119+
static Builder<?, ?> builder() {
120+
return new Builder<>();
121121
}
122122

123123
/**
124124
* Derives a new builder based on current instance of this class.
125125
*
126126
* @return a new builder instance
127127
*/
128-
Builder derive() {
129-
return new Builder().update(this);
128+
Builder<?, ?> derive() {
129+
return new Builder<>().update(this);
130130
}
131131

132132
Optional<SslContext> sslContext() {
@@ -319,6 +319,7 @@ static class Builder<B extends Builder<B, T>, T extends WebClientConfiguration>
319319
}
320320

321321
@Override
322+
@SuppressWarnings("unchecked")
322323
public T build() {
323324
return (T) new WebClientConfiguration(this);
324325
}

webclient/webclient/src/test/java/io/helidon/webclient/ProxyTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ void testNoProxyHandlingPredicate() {
7979
is("/foo/bar"));
8080
}
8181

82+
@Test
83+
void testDefaultProxyType() {
84+
Config config = Config.create();
85+
Proxy proxy = Proxy.create(config.get("proxy"));
86+
assertThat(proxy.type(), is(Proxy.ProxyType.HTTP));
87+
}
88+
8289
private URI address(String host, int port) {
8390
return URI.create("http://" + host + ":" + port);
8491
}

0 commit comments

Comments
 (0)