Changeset 35060 in osm for applications/editors
- Timestamp:
- 2019-07-09T02:24:55+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/http2/src/org/openstreetmap/josm/plugins/http2/Http2Client.java
r35059 r35060 14 14 import java.net.http.HttpResponse.BodyHandlers; 15 15 import java.time.Duration; 16 import java.time.LocalDateTime; 17 import java.time.ZoneOffset; 16 import java.time.Instant; 17 import java.time.ZoneId; 18 import java.time.ZonedDateTime; 18 19 import java.time.format.DateTimeFormatter; 19 20 import java.time.temporal.ChronoField; … … 25 26 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 26 27 import org.openstreetmap.josm.tools.JosmRuntimeException; 28 import org.openstreetmap.josm.tools.Logging; 27 29 import org.openstreetmap.josm.tools.Utils; 28 30 … … 42 44 @Override 43 45 protected void setupConnection(ProgressMonitor progressMonitor) throws IOException { 44 clientBuilder = HttpClient.newBuilder() 45 .connectTimeout(Duration.ofMillis(getConnectTimeout())) 46 .followRedirects(Redirect.NEVER); // we do that ourselves 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 51 try { 48 52 requestBuilder = HttpRequest.newBuilder() … … 51 55 ? BodyPublishers.ofByteArray(getRequestBody()) 52 56 : BodyPublishers.noBody()) 53 .header("User-Agent", Version.getInstance().getFullAgentString()) 54 .timeout(Duration.ofMillis(getReadTimeout())); 57 .header("User-Agent", Version.getInstance().getFullAgentString()); 55 58 } catch (URISyntaxException e) { 56 59 throw new IOException(e); 57 60 } 61 timeout = getReadTimeout(); 62 if (timeout > 0) { 63 requestBuilder.timeout(Duration.ofMillis(timeout)); 64 } 58 65 if (getIfModifiedSince() > 0) { 59 66 requestBuilder.header("If-Modified-Since", DateTimeFormatter.RFC_1123_DATE_TIME.format( 60 LocalDateTime.ofEpochSecond(getIfModifiedSince() / 1000, 0, ZoneOffset.UTC)));67 ZonedDateTime.ofInstant(Instant.ofEpochMilli(getIfModifiedSince()), ZoneId.systemDefault()))); 61 68 } 62 69 if (!isUseCache()) { … … 65 72 for (Map.Entry<String, String> header : getHeaders().entrySet()) { 66 73 if (header.getValue() != null) { 67 requestBuilder.header(header.getKey(), header.getValue()); 74 try { 75 requestBuilder.header(header.getKey(), header.getValue()); 76 } catch (IllegalArgumentException e) { 77 Logging.warn(e.getMessage()); 78 } 68 79 } 69 80 }
Note:
See TracChangeset
for help on using the changeset viewer.