Skip to content

Commit cbad67e

Browse files
committed
add chaining methods for HTTP clients configs
1 parent 923d7e4 commit cbad67e

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClientConfig.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public void setConnectTimeout(Integer connectTimeout) {
2828
this.connectTimeout = connectTimeout;
2929
}
3030

31+
public JDKHttpClientConfig withConnectTimeout(Integer connectTimeout) {
32+
this.connectTimeout = connectTimeout;
33+
return this;
34+
}
35+
3136
public Integer getReadTimeout() {
3237
return readTimeout;
3338
}
@@ -36,8 +41,9 @@ public void setReadTimeout(Integer readTimeout) {
3641
this.readTimeout = readTimeout;
3742
}
3843

39-
public boolean isFollowRedirects() {
40-
return followRedirects;
44+
public JDKHttpClientConfig withReadTimeout(Integer readTimeout) {
45+
this.readTimeout = readTimeout;
46+
return this;
4147
}
4248

4349
public void setProxy(Proxy proxy) {
@@ -48,6 +54,15 @@ public Proxy getProxy() {
4854
return proxy;
4955
}
5056

57+
public JDKHttpClientConfig withProxy(Proxy proxy) {
58+
this.proxy = proxy;
59+
return this;
60+
}
61+
62+
public boolean isFollowRedirects() {
63+
return followRedirects;
64+
}
65+
5166
/**
5267
* Sets whether the underlying Http Connection follows redirects or not.
5368
*
@@ -60,4 +75,19 @@ public Proxy getProxy() {
6075
public void setFollowRedirects(boolean followRedirects) {
6176
this.followRedirects = followRedirects;
6277
}
78+
79+
/**
80+
* Sets whether the underlying Http Connection follows redirects or not.
81+
*
82+
* Defaults to true (follow redirects)
83+
*
84+
* @see <a
85+
* href="http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean)">http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#setInstanceFollowRedirects(boolean)</a>
86+
* @param followRedirects boolean
87+
* @return this for chaining methods invocations
88+
*/
89+
public JDKHttpClientConfig withFollowRedirects(boolean followRedirects) {
90+
this.followRedirects = followRedirects;
91+
return this;
92+
}
6393
}

scribejava-httpclient-armeria/src/main/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientConfig.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public ArmeriaHttpClientConfig(ClientOptions clientOptions, ClientFactory client
3333

3434
/**
3535
* Creates new {@link HttpClientConfig} using default settings.
36+
*
37+
* @return new {@link HttpClientConfig} using default settings.
3638
*/
3739
@Override
3840
public HttpClientConfig createDefaultConfig() {
@@ -62,14 +64,29 @@ public void setProtocolPreference(SessionProtocol protocolPreference) {
6264
this.protocolPreference = protocolPreference;
6365
}
6466

67+
public ArmeriaHttpClientConfig withProtocolPreference(SessionProtocol protocolPreference) {
68+
setProtocolPreference(protocolPreference);
69+
return this;
70+
}
71+
6572
public void setRetry(Function<? super HttpClient, RetryingClient> retry) {
6673
this.retry = retry;
6774
}
6875

76+
public ArmeriaHttpClientConfig withRetry(Function<? super HttpClient, RetryingClient> retry) {
77+
this.retry = retry;
78+
return this;
79+
}
80+
6981
public void setLogging(Function<? super HttpClient, LoggingClient> logging) {
7082
this.logging = logging;
7183
}
7284

85+
public ArmeriaHttpClientConfig withLogging(Function<? super HttpClient, LoggingClient> logging) {
86+
this.logging = logging;
87+
return this;
88+
}
89+
7390
ArmeriaWebClientBuilder createClientBuilder() {
7491
return new ArmeriaWebClientBuilder(clientOptions, clientFactory, protocolPreference, retry, logging);
7592
}

scribejava-httpclient-armeria/src/test/java/com/github/scribejava/httpclient/armeria/ArmeriaHttpClientTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ protected HttpClient createNewClient() {
4747
.onStatus(HttpStatus.SERVICE_UNAVAILABLE)
4848
.onUnprocessed()
4949
.thenBackoff(retryBackoff);
50-
config.setRetry(RetryingClient.newDecorator(retryRule));
5150

52-
return new ArmeriaHttpClient(config);
51+
return new ArmeriaHttpClient(config.withRetry(RetryingClient.newDecorator(retryRule)));
5352
}
5453

5554
// No-Op DNS resolver to avoid resolution issues in the unit test

scribejava-httpclient-ning/src/main/java/com/github/scribejava/httpclient/ning/NingHttpClientConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public void setNingAsyncHttpProviderClassName(String ningAsyncHttpProviderClassN
2020
this.ningAsyncHttpProviderClassName = ningAsyncHttpProviderClassName;
2121
}
2222

23+
public NingHttpClientConfig withNingAsyncHttpProviderClassName(String ningAsyncHttpProviderClassName) {
24+
this.ningAsyncHttpProviderClassName = ningAsyncHttpProviderClassName;
25+
return this;
26+
}
27+
2328
public AsyncHttpClientConfig getConfig() {
2429
return config;
2530
}

0 commit comments

Comments
 (0)