Let mock server write response in UTF-8

This commit is contained in:
Dominik Przybysz 2015-06-17 11:36:41 +02:00
parent dbfb3727af
commit 57a6e06ac0
3 changed files with 45 additions and 6 deletions

View file

@ -4,9 +4,10 @@ import com.sun.net.httpserver.HttpExchange
class Util {
static void createResponse(HttpExchange ex, String response, int statusCode) {
ex.sendResponseHeaders(statusCode, response ? response.length() : -1)
byte[] responseBytes = response ? response.getBytes('UTF-8') : new byte[0]
ex.sendResponseHeaders(statusCode, responseBytes.length ?: -1)
if (response) {
ex.responseBody << response
ex.responseBody << responseBytes
ex.responseBody.close()
}
}