Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

fix: REGAPIC fix socket timeout for wait calls #1476

Merged
merged 1 commit into from Sep 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -54,6 +54,8 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.threeten.bp.Duration;
import org.threeten.bp.Instant;

/** A runnable object that creates and executes an HTTP request. */
@AutoValue
Expand Down Expand Up @@ -115,6 +117,16 @@ HttpRequest createHttpRequest() throws IOException {

HttpRequest httpRequest = buildRequest(requestFactory, url, jsonHttpContent);

Instant deadline = getHttpJsonCallOptions().getDeadline();
if (deadline != null) {
long readTimeout = Duration.between(Instant.now(), deadline).toMillis();
if (httpRequest.getReadTimeout() > 0
&& httpRequest.getReadTimeout() < readTimeout
&& readTimeout < Integer.MAX_VALUE) {
httpRequest.setReadTimeout((int) readTimeout);
}
}

for (HttpJsonHeaderEnhancer enhancer : getHeaderEnhancers()) {
enhancer.enhance(httpRequest.getHeaders());
}
Expand Down