Merge pull request #775 from Nitue/rfc7230-header-delimiter

RFC7230 compliant HTTP header delimiter

@Nitue
Thank you for your cooperation
This commit is contained in:
afischerdev 2025-04-05 13:00:46 +02:00 committed by GitHub
commit e3361cc113
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -160,8 +160,8 @@ public class RouteServer extends Thread implements Comparable<RouteServer> {
} else if (url.startsWith(PROFILE_UPLOAD_URL)) {
if (getline.startsWith("OPTIONS")) {
// handle CORS preflight request (Safari)
String corsHeaders = "Access-Control-Allow-Methods: GET, POST\n"
+ "Access-Control-Allow-Headers: Content-Type\n";
String corsHeaders = "Access-Control-Allow-Methods: GET, POST\r\n"
+ "Access-Control-Allow-Headers: Content-Type\r\n";
writeHttpHeader(bw, "text/plain", null, corsHeaders, HTTP_STATUS_OK);
bw.flush();
return;
@ -220,7 +220,7 @@ public class RouteServer extends Thread implements Comparable<RouteServer> {
// no zip for this engineMode
encodings = null;
}
String headers = encodings == null || encodings.indexOf("gzip") < 0 ? null : "Content-Encoding: gzip\n";
String headers = encodings == null || encodings.indexOf("gzip") < 0 ? null : "Content-Encoding: gzip\r\n";
writeHttpHeader(bw, handler.getMimeType(), handler.getFileName(), headers, HTTP_STATUS_OK);
if (engineMode == RoutingEngine.BROUTER_ENGINEMODE_ROUTING ||
engineMode == RoutingEngine.BROUTER_ENGINEMODE_ROUNDTRIP) {
@ -407,17 +407,17 @@ public class RouteServer extends Thread implements Comparable<RouteServer> {
private static void writeHttpHeader(BufferedWriter bw, String mimeType, String fileName, String headers, String status) throws IOException {
// http-header
bw.write(String.format("HTTP/1.1 %s\n", status));
bw.write("Connection: close\n");
bw.write("Content-Type: " + mimeType + "; charset=utf-8\n");
bw.write(String.format("HTTP/1.1 %s\r\n", status));
bw.write("Connection: close\r\n");
bw.write("Content-Type: " + mimeType + "; charset=utf-8\r\n");
if (fileName != null) {
bw.write("Content-Disposition: attachment; filename=\"" + fileName + "\"\n");
bw.write("Content-Disposition: attachment; filename=\"" + fileName + "\"\r\n");
}
bw.write("Access-Control-Allow-Origin: *\n");
bw.write("Access-Control-Allow-Origin: *\r\n");
if (headers != null) {
bw.write(headers);
}
bw.write("\n");
bw.write("\r\n");
}
private static void cleanupThreadQueue(Queue<RouteServer> threadQueue) {