Ignore:
Timestamp:
2020-03-01T01:02:22+01:00 (5 years ago)
Author:
simon04
Message:

fix #18812 - HttpClient: specify Accept=*/* to prevent Java from adding Accept=text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java

    r15742 r15968  
    8585        assertThat(client.getURL(), is(new URL("https://httpbin.org/")));
    8686        assertThat(client.getRequestMethod(), is("GET"));
    87         assertThat(client.getRequestHeader("Accept"), nullValue());
     87        assertThat(client.getRequestHeader("Accept"), is("*/*"));
    8888        client.setAccept("text/html");
    8989        assertThat(client.getRequestHeader("Accept"), is("text/html"));
     
    119119            assertThat(root.getJsonObject("headers").get("Cache-Control"), nullValue());
    120120            assertThat(root.getJsonObject("headers").get("Pragma"), nullValue());
     121        }
     122    }
     123
     124    /**
     125     * Test JOSM User-Agent
     126     * @throws IOException if an I/O error occurs
     127     */
     128    @Test
     129    public void testHeaders() throws IOException {
     130        try (InputStream in = HttpClient.create(new URL("https://httpbin.org/headers")).connect(progress).getContent();
     131             JsonReader json = JsonProvider.provider().createReader(in)) {
     132            final JsonObject headers = json.readObject().getJsonObject("headers");
     133            assertThat(headers.getString("Accept"), is("*/*"));
     134            assertThat(headers.getString("Accept-Encoding"), is("gzip, deflate"));
     135            assertThat(headers.getString("User-Agent"), is(Version.getInstance().getFullAgentString()));
    121136        }
    122137    }
Note: See TracChangeset for help on using the changeset viewer.