Skip to content

Commit 9a200c8

Browse files
committed
#4 - ENH: Add withVersion() and withExecutor() methods to HttpClientContext.Builder
1 parent bae7bbf commit 9a200c8

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

http-client/client/src/main/java/io/avaje/http/client/DHttpClientContextBuilder.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.net.CookieManager;
55
import java.net.http.HttpClient;
66
import java.time.Duration;
7+
import java.util.concurrent.Executor;
78

89
import static java.util.Objects.requireNonNull;
910

@@ -23,6 +24,9 @@ class DHttpClientContextBuilder implements HttpClientContext.Builder {
2324

2425
private HttpClient.Redirect redirect = HttpClient.Redirect.NORMAL;
2526

27+
private HttpClient.Version version;
28+
private Executor executor;
29+
2630
DHttpClientContextBuilder() {
2731
}
2832

@@ -67,6 +71,16 @@ public HttpClientContext.Builder withRedirect(HttpClient.Redirect redirect) {
6771
this.redirect = redirect;
6872
return this;
6973
}
74+
@Override
75+
public HttpClientContext.Builder withVersion(HttpClient.Version version) {
76+
this.version = version;
77+
return this;
78+
}
79+
@Override
80+
public HttpClientContext.Builder withExecutor(Executor executor) {
81+
this.executor = executor;
82+
return this;
83+
}
7084

7185
@Override
7286
public HttpClientContext build() {
@@ -86,6 +100,12 @@ private HttpClient defaultClient() {
86100
if (cookieHandler != null) {
87101
builder.cookieHandler(cookieHandler);
88102
}
103+
if (version != null) {
104+
builder.version(version);
105+
}
106+
if (executor != null) {
107+
builder.executor(executor);
108+
}
89109
return builder.build();
90110
}
91111

http-client/client/src/main/java/io/avaje/http/client/HttpClientContext.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.net.http.HttpClient;
55
import java.net.http.HttpResponse;
66
import java.time.Duration;
7+
import java.util.concurrent.Executor;
78

89
/**
910
* The HTTP client context that we use to build and process requests.
@@ -77,6 +78,8 @@ interface Builder {
7778

7879
/**
7980
* Set the underlying HttpClient to use.
81+
* <p>
82+
* Used when we wish to control all options of the HttpClient.
8083
*/
8184
Builder with(HttpClient client);
8285

@@ -87,6 +90,8 @@ interface Builder {
8790

8891
/**
8992
* Set the default request timeout.
93+
*
94+
* @see java.net.http.HttpRequest.Builder#timeout(Duration)
9095
*/
9196
Builder withRequestTimeout(Duration requestTimeout);
9297

@@ -105,14 +110,33 @@ interface Builder {
105110

106111
/**
107112
* Specify a cookie handler to use on the HttpClient. This would override the default cookie handler.
113+
*
114+
* @see HttpClient.Builder#cookieHandler(CookieHandler)
108115
*/
109116
Builder withCookieHandler(CookieHandler cookieHandler);
110117

111118
/**
112119
* Specify the redirect policy. Defaults to HttpClient.Redirect.NORMAL.
120+
*
121+
* @see HttpClient.Builder#followRedirects(HttpClient.Redirect)
113122
*/
114123
Builder withRedirect(HttpClient.Redirect redirect);
115124

125+
/**
126+
* Specify the HTTP version. Defaults to not set.
127+
*
128+
* @see HttpClient.Builder#version(HttpClient.Version)
129+
*/
130+
Builder withVersion(HttpClient.Version version);
131+
132+
/**
133+
* Specify the Executor to use for asynchronous tasks.
134+
* If not specified a default executor will be used.
135+
*
136+
* @see HttpClient.Builder#executor(Executor)
137+
*/
138+
Builder withExecutor(Executor executor);
139+
116140
/**
117141
* Build and return the context.
118142
*/

0 commit comments

Comments
 (0)