Browse Source

api: make sure to return when GET response is done

calling request->send() multiple times does not work as expected
mcspr-patch-1
Maxim Prokhorov 3 years ago
parent
commit
b0fb6b9851
1 changed files with 7 additions and 1 deletions
  1. +7
    -1
      code/espurna/api.cpp

+ 7
- 1
code/espurna/api.cpp View File

@ -277,6 +277,8 @@ bool _apiIsFormDataContent(AsyncWebServerRequest* request) {
// - Server never checks for request closing in filter or canHandle, so if we don't want to handle large content-length, it // - Server never checks for request closing in filter or canHandle, so if we don't want to handle large content-length, it
// will still flow through the lwip backend. // will still flow through the lwip backend.
// - `request->_tempObject` is used to keep API request state, but it's just a plain void pointer // - `request->_tempObject` is used to keep API request state, but it's just a plain void pointer
// - `request->send(..., payload)` creates a heap-allocated `reponse` object that will copy the payload and tracks it by a basic pointer.
// In case we call `request->send` a 2nd time (regardless of the type of the send()), it creates a 2nd object without de-allocating the 1st one.
// - espasyncwebserver will `free(_tempObject)` when request is disconnected, but only after this callbackhandler is done. // - espasyncwebserver will `free(_tempObject)` when request is disconnected, but only after this callbackhandler is done.
// make sure it's set to nullptr via `AsyncWebServerRequest::onDisconnect` // make sure it's set to nullptr via `AsyncWebServerRequest::onDisconnect`
// - ALL headers are parsed (and we could access those during filter and canHandle callbacks), but we need to explicitly // - ALL headers are parsed (and we could access those during filter and canHandle callbacks), but we need to explicitly
@ -597,6 +599,7 @@ public:
case HTTP_HEAD: case HTTP_HEAD:
request->send(204); request->send(204);
return; return;
case HTTP_GET: case HTTP_GET:
case HTTP_PUT: { case HTTP_PUT: {
auto& helper = *reinterpret_cast<ApiRequestHelper*>(request->_tempObject); auto& helper = *reinterpret_cast<ApiRequestHelper*>(request->_tempObject);
@ -622,10 +625,13 @@ public:
request->send(204); request->send(204);
return; return;
} }
break;
} }
default: default:
request->send(405); request->send(405);
return;
break;
} }
} }


Loading…
Cancel
Save