Skip to content

Commit

Permalink
Merge pull request #5 from baileyatwork/feature/httpclient-connection…
Browse files Browse the repository at this point in the history
…-timeout-param

Added http client connection timeout parameter to client constructor.
  • Loading branch information
martinspielmann authored Aug 16, 2020
2 parents 2c47b2e + cfec01a commit 7b8234b
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpResponse.BodySubscribers;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.List;
import java.util.logging.Logger;
import javax.script.ScriptEngine;
Expand Down Expand Up @@ -82,7 +83,7 @@ public class HaveIBeenPwnedApiClient {
* @see <a href="https://haveibeenpwned.com/API/Key">https://haveibeenpwned.com/API/Key</a>
*/
public HaveIBeenPwnedApiClient() {
this(null, null, null);
this(null, null, null, null);
}

/**
Expand All @@ -101,7 +102,7 @@ public HaveIBeenPwnedApiClient() {
* @see <a href="https://haveibeenpwned.com/API/Key">https://haveibeenpwned.com/API/Key</a>
*/
public HaveIBeenPwnedApiClient(String hibpApiKey) {
this(hibpApiKey, null, null);
this(hibpApiKey, null, null, null);
}

/**
Expand All @@ -121,7 +122,11 @@ public HaveIBeenPwnedApiClient(String hibpApiKey) {
* @see <a href="https://haveibeenpwned.com/API/Key">https://haveibeenpwned.com/API/Key</a>
*/
public HaveIBeenPwnedApiClient(String hibpApiKey, InetSocketAddress proxy) {
this(hibpApiKey, proxy, null);
this(hibpApiKey, proxy, null, null);
}

public HaveIBeenPwnedApiClient(String hibpApiKey, InetSocketAddress proxy, String userAgent) {
this(hibpApiKey, proxy, userAgent, null);
}

/**
Expand All @@ -137,12 +142,13 @@ public HaveIBeenPwnedApiClient(String hibpApiKey, InetSocketAddress proxy) {
* @param hibpApiKey the API key
* @param proxy the proxy
* @param userAgent the user agent
* @param connectionTimeout the connection timeout duration for the HttpClient
*
* @see <a href=
* "https://haveibeenpwned.com/API/v3#Authorisation">https://haveibeenpwned.com/API/v3#Authorisation</a>
* @see <a href="https://haveibeenpwned.com/API/Key">https://haveibeenpwned.com/API/Key</a>
*/
public HaveIBeenPwnedApiClient(String hibpApiKey, InetSocketAddress proxy, String userAgent) {
public HaveIBeenPwnedApiClient(String hibpApiKey, InetSocketAddress proxy, String userAgent, Duration connectionTimeout) {
super();
if (hibpApiKey != null) {
this.hibpApiKey = hibpApiKey;
Expand All @@ -156,6 +162,10 @@ public HaveIBeenPwnedApiClient(String hibpApiKey, InetSocketAddress proxy, Strin
if (proxy != null) {
builder.proxy(ProxySelector.of(proxy));
}
// set connection timeout if configured
if (connectionTimeout != null) {
builder.connectTimeout(connectionTimeout);
}
this.httpClient = builder.build();
if (userAgent != null) {
this.userAgent = userAgent;
Expand Down

0 comments on commit 7b8234b

Please sign in to comment.