Changeset 35921 in osm


Ignore:
Timestamp:
2022-03-03T15:14:49+01:00 (2 years ago)
Author:
taylor.smock
Message:

fix #21906: Properly use user set User-Agent header

This also enables the http2 plugin to be disabled without JOSM restart -- we
just set the HttpClient factory back to Http1Client::new. Ideally, users would
still restart JOSM to ensure that all classes are unloaded, but this should
make it easier to debug if an issue is due to http2 or something else.

Location:
applications/editors/josm/plugins/http2/src/org/openstreetmap/josm/plugins/http2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/http2/src/org/openstreetmap/josm/plugins/http2/Http2Client.java

    r35791 r35921  
    3737
    3838    private static final Map<Duration, HttpClient> clientForConnectTimeout = new ConcurrentHashMap<>();
     39    private static final String USER_AGENT_STRING = "User-Agent";
    3940    private HttpRequest request;
    4041    private HttpResponse<InputStream> response;
     
    5758    HttpRequest createRequest() throws IOException {
    5859        HttpRequest.Builder requestBuilder;
     60        Map<String, String> headers = getHeaders();
    5961        try {
    6062            requestBuilder = HttpRequest.newBuilder()
     
    6365                              ? BodyPublishers.ofByteArray(getRequestBody())
    6466                              : BodyPublishers.noBody())
    65                       .header("User-Agent", Version.getInstance().getFullAgentString());
     67                      .header(USER_AGENT_STRING, headers.getOrDefault(USER_AGENT_STRING, Version.getInstance().getFullAgentString()));
    6668        } catch (URISyntaxException e) {
    6769            throw new IOException(e);
     
    7880            requestBuilder.header("Cache-Control", "no-cache");
    7981        }
    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())) {
    8284                try {
    8385                    requestBuilder.header(header.getKey(), header.getValue());
  • applications/editors/josm/plugins/http2/src/org/openstreetmap/josm/plugins/http2/Http2Plugin.java

    r35053 r35921  
    44import org.openstreetmap.josm.plugins.Plugin;
    55import org.openstreetmap.josm.plugins.PluginInformation;
     6import org.openstreetmap.josm.tools.Destroyable;
     7import org.openstreetmap.josm.tools.Http1Client;
    68import org.openstreetmap.josm.tools.HttpClient;
    79
     
    911 * Provides HTTP/2 support.
    1012 */
    11 public class Http2Plugin extends Plugin {
     13public class Http2Plugin extends Plugin implements Destroyable {
    1214
    1315    /**
     
    1921        HttpClient.setFactory(Http2Client::new);
    2022    }
     23
     24    @Override
     25    public void destroy() {
     26        HttpClient.setFactory(Http1Client::new);
     27    }
    2128}
Note: See TracChangeset for help on using the changeset viewer.