Skip to content

Commit d9460a5

Browse files
horghclaude
andcommitted
Simplify httpClient validation logic
Use null defaults for connectTimeout and proxy in Builder, making validation cleaner by simply checking for null values. Set defaults only when no custom HttpClient is provided. Remove unnecessary comments. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent e075cc5 commit d9460a5

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/main/java/com/maxmind/geoip2/WebServiceClient.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ private WebServiceClient(Builder builder) {
141141

142142
requestTimeout = builder.requestTimeout;
143143

144-
// Use custom HttpClient if provided, otherwise create a default one
145144
if (builder.httpClient != null) {
146145
httpClient = builder.httpClient;
147146
} else {
@@ -177,11 +176,11 @@ public static final class Builder {
177176
int port = 443;
178177
boolean useHttps = true;
179178

180-
Duration connectTimeout = Duration.ofSeconds(3);
179+
Duration connectTimeout = null;
181180
Duration requestTimeout = Duration.ofSeconds(20);
182181

183182
List<String> locales = Collections.singletonList("en");
184-
private ProxySelector proxy = ProxySelector.getDefault();
183+
private ProxySelector proxy = null;
185184
private HttpClient httpClient = null;
186185

187186
/**
@@ -322,18 +321,23 @@ public Builder httpClient(HttpClient val) {
322321
*/
323322
public WebServiceClient build() {
324323
if (httpClient != null) {
325-
// Check if connectTimeout was changed from default
326-
if (!connectTimeout.equals(Duration.ofSeconds(3))) {
324+
if (connectTimeout != null) {
327325
throw new IllegalArgumentException(
328326
"Cannot set both httpClient and connectTimeout. "
329327
+ "Configure timeout on the provided HttpClient instead.");
330328
}
331-
// Check if proxy was changed from default
332-
if (proxy != ProxySelector.getDefault()) {
329+
if (proxy != null) {
333330
throw new IllegalArgumentException(
334331
"Cannot set both httpClient and proxy. "
335332
+ "Configure proxy on the provided HttpClient instead.");
336333
}
334+
} else {
335+
if (connectTimeout == null) {
336+
connectTimeout = Duration.ofSeconds(3);
337+
}
338+
if (proxy == null) {
339+
proxy = ProxySelector.getDefault();
340+
}
337341
}
338342
return new WebServiceClient(this);
339343
}

0 commit comments

Comments
 (0)