diff --git a/plugins/http2/src/org/openstreetmap/josm/plugins/http2/Http2Client.java b/plugins/http2/src/org/openstreetmap/josm/plugins/http2/Http2Client.java
index b322196fe..7e62eccac 100644
|
a
|
b
|
import org.openstreetmap.josm.tools.Utils;
|
| 36 | 36 | public final class Http2Client extends org.openstreetmap.josm.tools.HttpClient { |
| 37 | 37 | |
| 38 | 38 | private static final Map<Duration, HttpClient> clientForConnectTimeout = new ConcurrentHashMap<>(); |
| | 39 | private static final String USER_AGENT_STRING = "User-Agent"; |
| 39 | 40 | private HttpRequest request; |
| 40 | 41 | private HttpResponse<InputStream> response; |
| 41 | 42 | |
| … |
… |
public final class Http2Client extends org.openstreetmap.josm.tools.HttpClient {
|
| 56 | 57 | |
| 57 | 58 | HttpRequest createRequest() throws IOException { |
| 58 | 59 | HttpRequest.Builder requestBuilder; |
| | 60 | Map<String, String> headers = getHeaders(); |
| 59 | 61 | try { |
| 60 | 62 | requestBuilder = HttpRequest.newBuilder() |
| 61 | 63 | .uri(getURL().toURI()) |
| 62 | 64 | .method(getRequestMethod(), hasRequestBody() |
| 63 | 65 | ? BodyPublishers.ofByteArray(getRequestBody()) |
| 64 | 66 | : BodyPublishers.noBody()) |
| 65 | | .header("User-Agent", Version.getInstance().getFullAgentString()); |
| | 67 | .header(USER_AGENT_STRING, headers.getOrDefault(USER_AGENT_STRING, Version.getInstance().getFullAgentString())); |
| 66 | 68 | } catch (URISyntaxException e) { |
| 67 | 69 | throw new IOException(e); |
| 68 | 70 | } |
| … |
… |
public final class Http2Client extends org.openstreetmap.josm.tools.HttpClient {
|
| 77 | 79 | if (!isUseCache()) { |
| 78 | 80 | requestBuilder.header("Cache-Control", "no-cache"); |
| 79 | 81 | } |
| 80 | | for (Map.Entry<String, String> header : getHeaders().entrySet()) { |
| 81 | | if (header.getValue() != null) { |
| | 82 | for (Map.Entry<String, String> header : headers.entrySet()) { |
| | 83 | if (header.getValue() != null && !USER_AGENT_STRING.equals(header.getKey())) { |
| 82 | 84 | try { |
| 83 | 85 | requestBuilder.header(header.getKey(), header.getValue()); |
| 84 | 86 | } catch (IllegalArgumentException e) { |
diff --git a/plugins/http2/src/org/openstreetmap/josm/plugins/http2/Http2Plugin.java b/plugins/http2/src/org/openstreetmap/josm/plugins/http2/Http2Plugin.java
index dd2fc9061..1d8d4ca99 100644
|
a
|
b
|
package org.openstreetmap.josm.plugins.http2;
|
| 3 | 3 | |
| 4 | 4 | import org.openstreetmap.josm.plugins.Plugin; |
| 5 | 5 | import org.openstreetmap.josm.plugins.PluginInformation; |
| | 6 | import org.openstreetmap.josm.tools.Destroyable; |
| | 7 | import org.openstreetmap.josm.tools.Http1Client; |
| 6 | 8 | import org.openstreetmap.josm.tools.HttpClient; |
| 7 | 9 | |
| 8 | 10 | /** |
| 9 | 11 | * Provides HTTP/2 support. |
| 10 | 12 | */ |
| 11 | | public class Http2Plugin extends Plugin { |
| | 13 | public class Http2Plugin extends Plugin implements Destroyable { |
| 12 | 14 | |
| 13 | 15 | /** |
| 14 | 16 | * Constructs a new {@code Http2Plugin}. |
| … |
… |
public class Http2Plugin extends Plugin {
|
| 18 | 20 | super(info); |
| 19 | 21 | HttpClient.setFactory(Http2Client::new); |
| 20 | 22 | } |
| | 23 | |
| | 24 | @Override |
| | 25 | public void destroy() { |
| | 26 | HttpClient.setFactory(Http1Client::new); |
| | 27 | } |
| 21 | 28 | } |