Tests: Fix mockwebserver to parse incoming http bodies as UTF8

By not specifying a charset this used the system charset and
led to breaking tests under windows.

relates elastic/x-pack-elasticsearch#3498

Original commit: elastic/x-pack-elasticsearch@17d415ebbd
This commit is contained in:
Alexander Reelsen 2018-01-08 17:53:07 +01:00
parent f80f1dd268
commit 1d3c622746
2 changed files with 1 additions and 3 deletions

View File

@ -179,7 +179,7 @@ public class MockWebServer implements Closeable {
private MockRequest createRequest(HttpExchange exchange) throws IOException {
MockRequest request = new MockRequest(exchange.getRequestMethod(), exchange.getRequestURI(), exchange.getRequestHeaders());
if (exchange.getRequestBody() != null) {
String body = Streams.copyToString(new InputStreamReader(exchange.getRequestBody()));
String body = Streams.copyToString(new InputStreamReader(exchange.getRequestBody(), StandardCharsets.UTF_8));
if (Strings.isEmpty(body) == false) {
request.setBody(body);
}

View File

@ -10,7 +10,6 @@ import org.apache.http.HttpHeaders;
import org.apache.http.client.ClientProtocolException;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier;
import org.apache.lucene.util.Constants;
import org.elasticsearch.common.settings.MockSecureSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
@ -499,7 +498,6 @@ public class HttpClientTests extends ESTestCase {
}
public void testThatBodyWithUTF8Content() throws Exception {
assumeTrue("This test fails under windows, disabled temporary",Constants.WINDOWS == false);
String body = "title あいうえお";
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(body));