Skip to content

Commit b5ac98e

Browse files
http: timeout config value with 30s default value
1 parent 2d1f7b1 commit b5ac98e

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

webtau-config/src/main/java/org/testingisdocumenting/webtau/cfg/WebTauConfig.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public class WebTauConfig {
6060
"max number of lines to display in console for outputs (e.g. http response)", () -> 500);
6161

6262
private final ConfigValue waitTimeout = declare("waitTimeout", "wait timeout in milliseconds", () -> SystemTimerConfig.DEFAULT_WAIT_TIMEOUT);
63+
64+
private final ConfigValue httpTimeout = declare("httpTimeout", "http connect and read timeout in milliseconds", () -> 30000);
65+
6366
private final ConfigValue disableFollowingRedirects = declareBoolean("disableRedirects", "disable following of redirects from HTTP calls", false);
6467
private final ConfigValue maxRedirects = declare("maxRedirects", "Maximum number of redirects to follow for an HTTP call", () -> 20);
6568
private final ConfigValue userAgent = declare("userAgent", "User agent to send on HTTP requests",
@@ -201,10 +204,14 @@ public ConfigValue getBaseUrlConfigValue() {
201204
return url;
202205
}
203206

204-
public int waitTimeout() {
207+
public int getWaitTimeout() {
205208
return waitTimeout.getAsInt();
206209
}
207210

211+
public int getHttpTimeout() {
212+
return httpTimeout.getAsInt();
213+
}
214+
208215
public boolean shouldFollowRedirects() {
209216
return !disableFollowingRedirects.getAsBoolean();
210217
}

webtau-config/src/main/java/org/testingisdocumenting/webtau/cfg/WebTauCoreConfigHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
public class WebTauCoreConfigHandler implements WebTauConfigHandler {
3636
@Override
3737
public void onAfterCreate(WebTauConfig cfg) {
38-
SystemTimerConfig.setWaitTimeout(cfg.waitTimeout());
38+
SystemTimerConfig.setWaitTimeout(cfg.getWaitTimeout());
3939
DocumentationArtifactsLocation.setRoot(cfg.getDocArtifactsPath());
4040
}
4141
}

webtau-http/src/main/java/org/testingisdocumenting/webtau/http/Http.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,6 @@ public HttpResponse putToFullUrl(String fullUrl, HttpHeader requestHeader, HttpR
887887
return request("PUT", fullUrl, requestHeader, requestBody);
888888
}
889889

890-
@SuppressWarnings("unchecked")
891890
private <R> R executeAndValidateHttpCall(String requestMethod,
892891
String url,
893892
HttpCall httpCall,
@@ -902,7 +901,7 @@ private <R> R executeAndValidateHttpCall(String requestMethod,
902901

903902
WebTauStep step = createHttpStep(validationResult, httpCall, validator);
904903
try {
905-
return (R) step.execute(StepReportOptions.REPORT_ALL);
904+
return step.execute(StepReportOptions.REPORT_ALL);
906905
} finally {
907906
lastValidationResult.set(validationResult);
908907
step.addPayload(validationResult);
@@ -967,7 +966,7 @@ private HttpResponse followRedirects(String requestMethod, HttpCall httpCall, Ht
967966
int retryCount = 0;
968967
while (response.isRedirect() && getCfg().shouldFollowRedirects() && retryCount++ < getCfg().maxRedirects()) {
969968
WebTauStep httpStep = createRedirectStep(requestMethod, response.locationHeader(), httpCall, fullRequestHeader);
970-
response = (HttpResponse) httpStep.execute(StepReportOptions.REPORT_ALL);
969+
response = httpStep.execute(StepReportOptions.REPORT_ALL);
971970
}
972971
return response;
973972
}
@@ -1161,6 +1160,8 @@ private HttpResponse request(String method, String fullUrl,
11611160
HttpURLConnection connection = (HttpURLConnection) new URL(fullUrl).openConnection();
11621161
connection.setInstanceFollowRedirects(false);
11631162
setRequestMethod(method, connection);
1163+
connection.setConnectTimeout(getCfg().getHttpTimeout());
1164+
connection.setReadTimeout(getCfg().getHttpTimeout());
11641165
connection.setRequestProperty("Content-Type", requestBody.type());
11651166
connection.setRequestProperty("Accept", requestBody.type());
11661167
connection.setRequestProperty("User-Agent", getCfg().getUserAgent());

0 commit comments

Comments
 (0)