diff --git a/src/main/java/de/gnmyt/autoresponder/http/controller/HttpResponseController.java b/src/main/java/de/gnmyt/autoresponder/http/controller/HttpResponseController.java
index 223f5c4..d1be6b6 100644
--- a/src/main/java/de/gnmyt/autoresponder/http/controller/HttpResponseController.java
+++ b/src/main/java/de/gnmyt/autoresponder/http/controller/HttpResponseController.java
@@ -18,6 +18,8 @@ public class HttpResponseController {
private final Response response = new Response();
private final HttpExchange exchange;
+ private boolean responseSent = false;
+
/**
* Constructor of the {@link HttpResponseController}
*
@@ -64,6 +66,10 @@ public class HttpResponseController {
* Sends the response to the AutoResponder
*/
public void send() {
+ if (isResponseSent()) {
+ LOG.warn("Reply already sent, ignoring the message.");
+ return;
+ }
OutputStream os = exchange.getResponseBody();
response
@@ -86,10 +92,19 @@ public class HttpResponseController {
exchange.sendResponseHeaders(response.getCode(), bs.length);
os.write(bs);
}
+ responseSent = true;
os.close();
} catch (IOException e) {
LOG.error("Could not process response: " + e.getMessage());
}
}
+ /**
+ * Checks if the response has already been sent
+ *
+ * @return true
if the response has already been sent, otherwise false
+ */
+ public boolean isResponseSent() {
+ return responseSent;
+ }
}