Fix sorting problems

This commit is contained in:
DevSnaith 2023-04-14 02:36:02 +03:00
parent 24a07e1fa5
commit 596e2d9a23
2 changed files with 4 additions and 5 deletions

View File

@ -2,7 +2,7 @@ package org.eu.lumiere.net.http;
import java.io.IOException;
import java.net.Socket;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Set;
import org.eu.lumiere.loggers.GlobalLogger;
@ -13,22 +13,21 @@ public class HttpResponse {
private GlobalLogger l = GlobalLogger.getLogger();
private String status_line = "HTTP/1.0 200 OK";
private String content_type = "text/html";
private HashMap<String, String> httph;
private LinkedHashMap<String, String> httph;
private Socket client;
public HttpResponse(Socket client, String status_line, String content_type) {
this.content_type = content_type == null ? this.content_type : content_type;
if(status_line != null && !status_line.isEmpty())
this.status_line = status_line;
httph = httph == null ? new HashMap<>() : httph;
httph = httph == null ? new LinkedHashMap<>() : httph;
this.client = client;
}
public void push(String body) {
try {
StringBuilder build = new StringBuilder(status_line+"\r\n");
for(String key : getKeySet()) {
for(String key : httph.keySet()) {
build.append(String.format("%s: %s\r\n", key, getProperty(key)));
}
client.getOutputStream().write(build.append("\r\n").append(body).toString().getBytes());