Skip to content

Commit

Permalink
Merge pull request #1654 from proddy/dev
Browse files Browse the repository at this point in the history
cleanup and making asyncWS cleaner
  • Loading branch information
proddy authored Mar 10, 2024
2 parents c5f2dba + c1ae0e7 commit 7fc7c24
Show file tree
Hide file tree
Showing 29 changed files with 2,215 additions and 1,998 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# vscode
.vscode/c_cpp_properties.json
.vscode/extensions.json
.vscode/launch.json
.vscode/settings.json
.vscode/*

# c++ compiling
.clang_complete
Expand Down Expand Up @@ -60,3 +57,4 @@ bw-output/

# testing
emsesp

2 changes: 0 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"platformio.platformio-ide"
],
"unwantedRecommendations": [
Expand Down
88 changes: 0 additions & 88 deletions .vscode/settings.json

This file was deleted.

18 changes: 0 additions & 18 deletions .vscode/tasks.json

This file was deleted.

23 changes: 15 additions & 8 deletions lib/ESPAsyncWebServer/src/AsyncJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AsyncJsonResponse : public AsyncAbstractResponse {

~AsyncJsonResponse() {
}
JsonVariant & getRoot() {
JsonVariant getRoot() {
return _root;
}
bool _sourceValid() const {
Expand Down Expand Up @@ -108,7 +108,7 @@ class PrettyAsyncJsonResponse : public AsyncJsonResponse {
}
};

typedef std::function<void(AsyncWebServerRequest * request, JsonVariant & json)> ArJsonRequestHandlerFunction;
typedef std::function<void(AsyncWebServerRequest * request, JsonVariant json)> ArJsonRequestHandlerFunction;

class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
private:
Expand Down Expand Up @@ -142,32 +142,39 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
if (!_onRequest)
return false;

if (!(_method & request->method()))
WebRequestMethodComposite request_method = request->method();

if (!(_method & request_method))
return false;

if (_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri + "/")))
return false;

if (!request->contentType().equalsIgnoreCase(JSON_MIMETYPE))
if (request_method != HTTP_GET && !request->contentType().equalsIgnoreCase(JSON_MIMETYPE))
return false;

request->addInterestingHeader("ANY");
return true;
}

virtual void handleRequest(AsyncWebServerRequest * request) override final {
if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str()))
return request->requestAuthentication();
if (_onRequest) {
JsonVariant json; // empty variant
if (request->_tempObject != NULL) {
if (request->method() == HTTP_GET) {
JsonVariant json;
_onRequest(request, json);
return;
} else if (request->_tempObject != NULL) {
JsonDocument jsonBuffer;
DeserializationError error = deserializeJson(jsonBuffer, (uint8_t *)(request->_tempObject));
if (!error) {
json = jsonBuffer.as<JsonVariant>();
JsonVariant json = jsonBuffer.as<JsonVariant>();
_onRequest(request, json);
return;
}
}
_onRequest(request, json);
request->send(_contentLength > _maxContentLength ? 413 : 400);
} else {
request->send(500);
}
Expand Down
Loading

0 comments on commit 7fc7c24

Please sign in to comment.