Pass full InetSocketAddress

This commit is contained in:
cedb 2022-11-01 15:37:27 -04:00
parent 60c40e7490
commit 0ce9ddb220
2 changed files with 10 additions and 9 deletions

View file

@ -136,7 +136,7 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
final var httpAddress = ns.getString("http"); final var httpAddress = ns.getString("http");
if (httpAddress != null) { if (httpAddress != null) {
final var address = IOUtils.parseInetSocketAddress(httpAddress); final var address = IOUtils.parseInetSocketAddress(httpAddress);
final var handler = new HttpServerHandler(address.getPort(), m); final var handler = new HttpServerHandler(address, m);
handler.init(); handler.init();
} }
final var isDbusSystem = Boolean.TRUE.equals(ns.getBoolean("dbus-system")); final var isDbusSystem = Boolean.TRUE.equals(ns.getBoolean("dbus-system"));
@ -213,7 +213,7 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
final var httpAddress = ns.getString("http"); final var httpAddress = ns.getString("http");
if (httpAddress != null) { if (httpAddress != null) {
final var address = IOUtils.parseInetSocketAddress(httpAddress); final var address = IOUtils.parseInetSocketAddress(httpAddress);
final var handler = new HttpServerHandler(address.getPort(), c); final var handler = new HttpServerHandler(address, c);
handler.init(); handler.init();
} }
final var isDbusSystem = Boolean.TRUE.equals(ns.getBoolean("dbus-system")); final var isDbusSystem = Boolean.TRUE.equals(ns.getBoolean("dbus-system"));

View file

@ -25,20 +25,20 @@ public class HttpServerHandler {
private final ObjectMapper objectMapper = Util.createJsonObjectMapper(); private final ObjectMapper objectMapper = Util.createJsonObjectMapper();
private final int port; private final InetSocketAddress address;
private final Manager m; private final Manager m;
private final MultiAccountManager c; private final MultiAccountManager c;
public HttpServerHandler(final int port, final Manager m) { public HttpServerHandler(final InetSocketAddress address, final Manager m) {
this.port = port; this.address = address;
this.m = m; this.m = m;
this.c = null; this.c = null;
} }
public HttpServerHandler(final int port, final MultiAccountManager c) { public HttpServerHandler(final InetSocketAddress address, final MultiAccountManager c) {
this.port = port; this.address = address;
this.m = null; this.m = null;
this.c = c; this.c = c;
} }
@ -47,15 +47,16 @@ public class HttpServerHandler {
try { try {
logger.info("Starting server on port " + port); logger.info("Starting server on port " + address.toString());
final var server = HttpServer.create(new InetSocketAddress(port), 0); final var server = HttpServer.create(new InetSocketAddress(address.getPort()), 0);
server.setExecutor(Executors.newFixedThreadPool(10)); server.setExecutor(Executors.newFixedThreadPool(10));
server.createContext("/api/v1/rpc", httpExchange -> { server.createContext("/api/v1/rpc", httpExchange -> {
if (!"POST".equals(httpExchange.getRequestMethod())) { if (!"POST".equals(httpExchange.getRequestMethod())) {
sendResponse(405, null, httpExchange); sendResponse(405, null, httpExchange);
return;
} }
try { try {