FIXED UTF-8 CHAR ENCODING ISSUE (Fixes #291 #331)

This commit is contained in:
Rsl1122 2018-07-30 11:21:27 +03:00
parent df50b8bb76
commit a35da3dad2
2 changed files with 6 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import com.sun.net.httpserver.HttpExchange;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.zip.GZIPOutputStream;
@ -87,10 +88,12 @@ public abstract class Response {
responseHeaders.set("Content-Encoding", "gzip");
exchange.sendResponseHeaders(getCode(), 0);
String content = this instanceof JavaScriptResponse ? getContent() : locale.replaceMatchingLanguage(getContent());
String content = this instanceof JavaScriptResponse
? getContent()
: locale.replaceMatchingLanguage(getContent());
try (GZIPOutputStream out = new GZIPOutputStream(exchange.getResponseBody());
ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes())) {
ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) {
byte[] buffer = new byte[2048];
int count;
while ((count = bis.read(buffer)) != -1) {

View File

@ -10,7 +10,7 @@ package com.djrapitops.plan.system.webserver.response;
* @author Rsl1122
*/
public enum ResponseType {
HTML("text/html;charset=utf-8"),
HTML("text/html; charset=utf-8"),
CSS("text/css"),
JSON("application/json"),
JAVASCRIPT("application/javascript");