diff options
Diffstat (limited to 'src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java')
-rw-r--r-- | src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java b/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java index bab9df2..1055e4f 100644 --- a/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java +++ b/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java @@ -102,11 +102,11 @@ public final class RouteSelector { * * @throws NoSuchElementException if there are no more routes to attempt. */ - public Connection next() throws IOException { + public Connection next(String method) throws IOException { // Always prefer pooled connections over new connections. - Connection pooled = pool.get(address); - if (pooled != null) { - return pooled; + for (Connection pooled; (pooled = pool.get(address)) != null; ) { + if (method.equals("GET") || pooled.isReadable()) return pooled; + pooled.close(); } // Compute the next route to attempt. @@ -131,7 +131,7 @@ public final class RouteSelector { postponedRoutes.add(route); // We will only recurse in order to skip previously failed routes. They will be // tried last. - return next(); + return next(method); } return new Connection(route); |