Skip to content

Commit

Permalink
Use the same timings for OkHttp as we do for the Apache HttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Stewart committed Feb 7, 2018
1 parent 027bb4f commit 63f7b50
Showing 1 changed file with 20 additions and 4 deletions.
Expand Up @@ -17,7 +17,7 @@

package org.openqa.selenium.remote.internal;

import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

import com.google.common.base.Strings;

Expand All @@ -35,8 +35,9 @@

import java.io.IOException;
import java.net.URL;
import java.time.Duration;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

public class OkHttpClient implements HttpClient {

Expand Down Expand Up @@ -118,15 +119,30 @@ public void close() {

public static class Factory implements HttpClient.Factory {

private ConnectionPool pool = new ConnectionPool();
private final ConnectionPool pool = new ConnectionPool();
private final long connectionTimeout;
private final long readTimeout;

public Factory() {
this(Duration.ofMinutes(2), Duration.ofHours(3));
}

public Factory(Duration connectionTimeout, Duration readTimeout) {
Objects.requireNonNull(connectionTimeout, "Connection timeout cannot be null");
Objects.requireNonNull(readTimeout, "Read timeout cannot be null");

this.connectionTimeout = connectionTimeout.toMillis();
this.readTimeout = readTimeout.toMillis();
}

@Override
public HttpClient createClient(URL url) {
okhttp3.OkHttpClient.Builder client = new okhttp3.OkHttpClient.Builder()
.connectionPool(pool)
.followRedirects(true)
.followSslRedirects(true)
.readTimeout(0, MINUTES);
.readTimeout(readTimeout, MILLISECONDS)
.connectTimeout(connectionTimeout, MILLISECONDS);

String info = url.getUserInfo();
if (!Strings.isNullOrEmpty(info)) {
Expand Down

0 comments on commit 63f7b50

Please sign in to comment.