Add connection timeout for forked ratpack http client (#3239)
This commit is contained in:
parent
e93ff4d419
commit
52b23d116e
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
package client
|
package client
|
||||||
|
|
||||||
|
import java.time.Duration
|
||||||
import ratpack.exec.Promise
|
import ratpack.exec.Promise
|
||||||
import ratpack.http.client.HttpClient
|
import ratpack.http.client.HttpClient
|
||||||
|
|
||||||
|
@ -13,6 +14,8 @@ class RatpackForkedHttpClientTest extends RatpackHttpClientTest {
|
||||||
@Override
|
@Override
|
||||||
Promise<Integer> internalSendRequest(HttpClient client, String method, URI uri, Map<String, String> headers) {
|
Promise<Integer> internalSendRequest(HttpClient client, String method, URI uri, Map<String, String> headers) {
|
||||||
def resp = client.request(uri) { spec ->
|
def resp = client.request(uri) { spec ->
|
||||||
|
// Connect timeout for the whole client was added in 1.5 so we need to add timeout for each request
|
||||||
|
spec.connectTimeout(Duration.ofSeconds(2))
|
||||||
spec.method(method)
|
spec.method(method)
|
||||||
spec.headers { headersSpec ->
|
spec.headers { headersSpec ->
|
||||||
headers.entrySet().each {
|
headers.entrySet().each {
|
||||||
|
|
|
@ -46,7 +46,6 @@ class RatpackHttpClientTest extends HttpClientTest<Void> implements AgentTestTra
|
||||||
HttpClient buildHttpClient(Action<? super HttpClientSpec> action) {
|
HttpClient buildHttpClient(Action<? super HttpClientSpec> action) {
|
||||||
HttpClient.of {
|
HttpClient.of {
|
||||||
it.readTimeout(Duration.ofSeconds(2))
|
it.readTimeout(Duration.ofSeconds(2))
|
||||||
// Connect timeout added in 1.5
|
|
||||||
// execController method added in 1.9
|
// execController method added in 1.9
|
||||||
if (HttpClientSpec.metaClass.getMetaMethod("execController") != null) {
|
if (HttpClientSpec.metaClass.getMetaMethod("execController") != null) {
|
||||||
it.execController(exec.getController())
|
it.execController(exec.getController())
|
||||||
|
@ -81,6 +80,7 @@ class RatpackHttpClientTest extends HttpClientTest<Void> implements AgentTestTra
|
||||||
// overridden in RatpackForkedHttpClientTest
|
// overridden in RatpackForkedHttpClientTest
|
||||||
Promise<Integer> internalSendRequest(HttpClient client, String method, URI uri, Map<String, String> headers) {
|
Promise<Integer> internalSendRequest(HttpClient client, String method, URI uri, Map<String, String> headers) {
|
||||||
def resp = client.request(uri) { spec ->
|
def resp = client.request(uri) { spec ->
|
||||||
|
// Connect timeout for the whole client was added in 1.5 so we need to add timeout for each request
|
||||||
spec.connectTimeout(Duration.ofSeconds(2))
|
spec.connectTimeout(Duration.ofSeconds(2))
|
||||||
spec.method(method)
|
spec.method(method)
|
||||||
spec.headers { headersSpec ->
|
spec.headers { headersSpec ->
|
||||||
|
|
Loading…
Reference in New Issue