Bug fixes (im frustrated)

This commit is contained in:
UnlegitDqrk
2026-02-08 21:40:23 +01:00
parent 68802e4317
commit e3fee17a73
7 changed files with 127 additions and 33 deletions

View File

@@ -0,0 +1,32 @@
package org.openautonomousconnection.webserver.utils;
import java.util.HashMap;
import java.util.Map;
/**
* Small helper utilities for mutable header maps.
*/
public final class HeaderMaps {
private HeaderMaps() {
}
/**
* Creates an empty mutable header map.
*
* @return mutable map
*/
public static Map<String, String> mutable() {
return new HashMap<>();
}
/**
* Creates a mutable header map initialized with the given entries.
*
* @param initial initial entries (may be null)
* @return mutable map
*/
public static Map<String, String> mutable(Map<String, String> initial) {
return (initial == null || initial.isEmpty()) ? new HashMap<>() : new HashMap<>(initial);
}
}

View File

@@ -43,7 +43,7 @@ public final class HttpsProxy {
return new WebResponsePacket(
502,
"text/plain; charset=utf-8",
Map.of(),
HeaderMaps.mutable(),
("Bad Gateway: " + e.getClass().getName() + ": " + e.getMessage()).getBytes(StandardCharsets.UTF_8)
);
}
@@ -54,7 +54,7 @@ public final class HttpsProxy {
return new WebResponsePacket(
508,
"text/plain; charset=utf-8",
Map.of(),
HeaderMaps.mutable(),
"Too many redirects".getBytes(StandardCharsets.UTF_8)
);
}
@@ -82,7 +82,7 @@ public final class HttpsProxy {
return new WebResponsePacket(
502,
"text/plain; charset=utf-8",
Map.of(),
HeaderMaps.mutable(),
("Bad Gateway: redirect without Location (code=" + code + ")").getBytes(StandardCharsets.UTF_8)
);
}
@@ -104,8 +104,7 @@ public final class HttpsProxy {
con.disconnect();
}
Map<String, String> headers = new HashMap<>();
return new WebResponsePacket(code, contentType, headers, body);
return new WebResponsePacket(code, contentType, HeaderMaps.mutable(), body);
}
private static byte[] readAllBytes(InputStream in) throws Exception {