}
dbSession.commit();
- response.stream().setMediaType(guessMediaType(request));
+ response.stream().setMediaType(request.getMediaType());
JsonWriter jsonWriter = JsonWriter.of(new OutputStreamWriter(response.stream().output(), StandardCharsets.UTF_8));
writeResult(jsonWriter, result);
} finally {
}
}
- private static String guessMediaType(Request request) {
- if (request.getMediaType().contains("html")) {
- // this is a hack for IE.
- // The form which uploads files (for example PMD or Findbugs configuration files) opens a popup
- // to download files if the response type header is application/json. Changing the response type to text/plain,
- // even if response body is JSON, fixes the bug.
- // This will be fixed in 5.3 when support of IE9/10 will be dropped in order to use
- // more recent JS libs.
- // We detect that caller is IE because it asks for application/html or text/html
- return MediaTypes.TXT;
- }
- return request.getMediaType();
- }
-
private void writeResult(JsonWriter json, QProfileResult result) {
String language = result.profile().getLanguage();
json.beginObject().name("profile").beginObject()
JsonAssert.assertJson(response.getInput()).isSimilarTo(getClass().getResource("CreateActionTest/create-no-importer.json"));
assertThat(response.getMediaType()).isEqualTo(MediaTypes.JSON);
}
-
- /**
- * Do not return JSON content type header on IE.
- */
- @Test
- public void test_ie_hack() throws Exception {
- CreateAction underTest = new CreateAction(db.getDbClient(), new QProfileFactory(deprecatedDbClient), null, LanguageTesting.newLanguages("xoo"), userSessionRule);
- WsActionTester wsTester = new WsActionTester(underTest);
- userSessionRule.login("admin").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
-
- TestResponse response = wsTester.newRequest()
- .setMethod("POST")
- // IE asks for application/html or text/html
- .setMediaType("application/html")
- .setParam("language", "xoo")
- .setParam("name", "Yeehaw!")
- .execute();
- assertThat(response.getMediaType()).isEqualTo(MediaTypes.TXT);
-
- }
}