Skip to content

Commit 055c4c7

Browse files
committed
Don't enforce a maximum request timeout
Since requests may be slow (particularly if chunked and large), this allows you to configure the request / client to accept very large timeouts. You can also disable the timeout by providing a 0 or negative value.
1 parent 7ba8bbd commit 055c4c7

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

client/src/main/java/org/threadly/litesockets/client/http/HTTPClient.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,11 @@ public void closeAllClients() {
219219
* @param unit The unit the {@code timeout} value is represented in
220220
*/
221221
public void setTimeout(long timeout, TimeUnit unit) {
222-
this.defaultTimeoutMS = Math.min(Math.max(unit.toMillis(timeout),HTTPRequest.MIN_TIMEOUT_MS),
223-
HTTPRequest.MAX_TIMEOUT_MS);
222+
if (timeout <= 0) {
223+
this.defaultTimeoutMS = -1;
224+
} else {
225+
this.defaultTimeoutMS = Math.max(unit.toMillis(timeout), HTTPRequest.MIN_TIMEOUT_MS);
226+
}
224227
}
225228

226229
/**
@@ -635,7 +638,9 @@ private HTTPRequestWrapper(ClientHTTPRequest chr) {
635638
hrp.addHTTPResponseCallback(this);
636639
this.chr = chr;
637640

638-
sei.watchFuture(slf, chr.getTimeoutMS());
641+
if (chr.getTimeoutMS() > 0) {
642+
sei.watchFuture(slf, chr.getTimeoutMS());
643+
}
639644
slf.failureCallback((t) -> {
640645
if (queue.remove(this)) {
641646
// was likely a timeout, avoid leaving the request suck in the queue
@@ -663,10 +668,6 @@ public void processIncomingData(ReuseableMergedByteBuffers read) {
663668
hrp.processData(read);
664669
}
665670

666-
public long timeTillExpired() {
667-
return chr.getTimeoutMS() - (Clock.lastKnownForwardProgressingMillis() - lastRead);
668-
}
669-
670671
@Override
671672
public void headersFinished(HTTPResponse hr) {
672673
currentState = RequestState.ReadingResponseBody;

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group = org.threadly
2-
version = 0.26-SNAPSHOT
2+
version = 0.26
33
threadlyVersion = 5.39
44
litesocketsVersion = 4.10
55
org.gradle.parallel=false

protocol/src/main/java/org/threadly/litesockets/protocols/http/request/HTTPRequest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
public class HTTPRequest {
1515
public static final int DEFAULT_TIMEOUT_MS = 20000;
1616
public static final int MIN_TIMEOUT_MS = 500;
17-
public static final int MAX_TIMEOUT_MS = 300000;
1817

1918
private final HTTPRequestHeader request;
2019
private final HTTPHeaders headers;

protocol/src/main/java/org/threadly/litesockets/protocols/http/request/HTTPRequestBuilder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,12 @@ public HTTPRequestBuilder setBodyConsumer(BodyConsumer bodyConsumer) {
445445
return this;
446446
}
447447

448-
public HTTPRequestBuilder setTimeout(long size, TimeUnit unit) {
449-
this.timeoutMS = (int)Math.min(Math.max(unit.toMillis(size),HTTPRequest.MIN_TIMEOUT_MS), HTTPRequest.MAX_TIMEOUT_MS);
448+
public HTTPRequestBuilder setTimeout(long value, TimeUnit unit) {
449+
if (value <= 0) {
450+
this.timeoutMS = -1;
451+
} else {
452+
this.timeoutMS = (int)Math.max(unit.toMillis(value), HTTPRequest.MIN_TIMEOUT_MS);
453+
}
450454
return this;
451455
}
452456

0 commit comments

Comments
 (0)