From 227d3e6620b102a7333619ba17c0bb4097be4a8f Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Thu, 17 Dec 2020 03:38:53 +0300 Subject: [PATCH] api: allow to handle the request only once --- code/espurna/api_impl.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/espurna/api_impl.h b/code/espurna/api_impl.h index b1444489..57fbe492 100644 --- a/code/espurna/api_impl.h +++ b/code/espurna/api_impl.h @@ -111,6 +111,7 @@ struct ApiRequest { template void handle(T&& handler) { + if (_done) return; _done = true; handler(&_request); } @@ -143,12 +144,14 @@ struct ApiRequest { } void send(const String& payload) { + if (_done) return; + _done = true; + if (payload.length()) { _request.send(200, "text/plain", payload); } else { _request.send(204); } - _done = true; } bool done() const {