Changeset 35356 in osm for applications/editors/josm/plugins
- Timestamp:
- 2020-03-10T16:43:52+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/http2/src/org/openstreetmap/josm/plugins/http2/Http2Client.java
r35062 r35356 22 22 import java.util.Map; 23 23 import java.util.Objects; 24 import java.util.concurrent.ConcurrentHashMap; 24 25 25 26 import org.openstreetmap.josm.data.Version; … … 34 35 public final class Http2Client extends org.openstreetmap.josm.tools.HttpClient { 35 36 36 private HttpClient.Builder clientBuilder;37 private HttpRequest .Builder requestBuilder;37 private static final Map<Duration, HttpClient> clientForConnectTimeout = new ConcurrentHashMap<>(); 38 private HttpRequest request; 38 39 private HttpResponse<InputStream> response; 39 40 … … 44 45 @Override 45 46 protected void setupConnection(ProgressMonitor progressMonitor) throws IOException { 46 clientBuilder = HttpClient.newBuilder().followRedirects(Redirect.NEVER); // we do that ourselves 47 int timeout = getConnectTimeout(); 48 if (timeout > 0) { 49 clientBuilder.connectTimeout(Duration.ofMillis(timeout)); 50 } 47 HttpRequest.Builder requestBuilder; 51 48 try { 52 49 requestBuilder = HttpRequest.newBuilder() … … 59 56 throw new IOException(e); 60 57 } 61 timeout = getReadTimeout();58 int timeout = getReadTimeout(); 62 59 if (timeout > 0) { 63 60 requestBuilder.timeout(Duration.ofMillis(timeout)); … … 79 76 } 80 77 } 78 request = requestBuilder.build(); 81 79 82 80 notifyConnect(progressMonitor); … … 89 87 @Override 90 88 protected ConnectionResponse performConnection() throws IOException { 89 // reuse HttpClient 90 HttpClient client = clientForConnectTimeout.computeIfAbsent(Duration.ofMillis(getConnectTimeout()), timeout -> 91 HttpClient.newBuilder() 92 .followRedirects(Redirect.NEVER) // we do that ourselves 93 .connectTimeout(timeout) 94 .build()); 91 95 try { 92 response = client Builder.build().send(requestBuilder.build(), BodyHandlers.ofInputStream());96 response = client.send(request, BodyHandlers.ofInputStream()); 93 97 return new ConnectionResponse() { 94 98 @Override
Note:
See TracChangeset
for help on using the changeset viewer.