Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions examples/HTTPMethodsWithArduino/HTTPMethodsWithArduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ void setup() {

server.begin();

WebRequestMethodComposite composite1 = WebRequestMethod::HTTP_GET | WebRequestMethod::HTTP_POST;
WebRequestMethodComposite composite2 = WebRequestMethod::HTTP_GET | WebRequestMethod::HTTP_POST;
WebRequestMethodComposite composite3 = WebRequestMethod::HTTP_HEAD | WebRequestMethod::HTTP_OPTIONS;
WebRequestMethodComposite composite1 = AsyncWebRequestMethod::HTTP_GET | AsyncWebRequestMethod::HTTP_POST;
WebRequestMethodComposite composite2 = AsyncWebRequestMethod::HTTP_GET | AsyncWebRequestMethod::HTTP_POST;
WebRequestMethodComposite composite3 = AsyncWebRequestMethod::HTTP_HEAD | AsyncWebRequestMethod::HTTP_OPTIONS;
WebRequestMethodComposite composite4 = composite3;
WebRequestMethodComposite composite5 = WebRequestMethod::HTTP_GET;
WebRequestMethodComposite composite5 = AsyncWebRequestMethod::HTTP_GET;

assert(composite1.matches(WebRequestMethod::HTTP_GET));
assert(composite1.matches(WebRequestMethod::HTTP_POST));
assert(!composite1.matches(WebRequestMethod::HTTP_HEAD));
assert(!composite3.matches(WebRequestMethod::HTTP_GET));
assert(composite1.matches(AsyncWebRequestMethod::HTTP_GET));
assert(composite1.matches(AsyncWebRequestMethod::HTTP_POST));
assert(!composite1.matches(AsyncWebRequestMethod::HTTP_HEAD));
assert(!composite3.matches(AsyncWebRequestMethod::HTTP_GET));

assert(composite1 == composite2);
assert(composite3 == composite4);
Expand Down
16 changes: 8 additions & 8 deletions examples/HTTPMethodsWithESPIDF/HTTPMethodsWithESPIDF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ void setup() {

server.begin();

WebRequestMethodComposite composite1 = WebRequestMethod::HTTP_GET | WebRequestMethod::HTTP_POST;
WebRequestMethodComposite composite2 = WebRequestMethod::HTTP_GET | WebRequestMethod::HTTP_POST;
WebRequestMethodComposite composite3 = WebRequestMethod::HTTP_HEAD | WebRequestMethod::HTTP_OPTIONS;
WebRequestMethodComposite composite1 = AsyncWebRequestMethod::HTTP_GET | AsyncWebRequestMethod::HTTP_POST;
WebRequestMethodComposite composite2 = AsyncWebRequestMethod::HTTP_GET | AsyncWebRequestMethod::HTTP_POST;
WebRequestMethodComposite composite3 = AsyncWebRequestMethod::HTTP_HEAD | AsyncWebRequestMethod::HTTP_OPTIONS;
WebRequestMethodComposite composite4 = composite3;
WebRequestMethodComposite composite5 = WebRequestMethod::HTTP_GET;
WebRequestMethodComposite composite5 = AsyncWebRequestMethod::HTTP_GET;

assert(composite1.matches(WebRequestMethod::HTTP_GET));
assert(composite1.matches(WebRequestMethod::HTTP_POST));
assert(!composite1.matches(WebRequestMethod::HTTP_HEAD));
assert(!composite3.matches(WebRequestMethod::HTTP_GET));
assert(composite1.matches(AsyncWebRequestMethod::HTTP_GET));
assert(composite1.matches(AsyncWebRequestMethod::HTTP_POST));
assert(!composite1.matches(AsyncWebRequestMethod::HTTP_HEAD));
assert(!composite3.matches(AsyncWebRequestMethod::HTTP_GET));

assert(composite1 == composite2);
assert(composite3 == composite4);
Expand Down
15 changes: 9 additions & 6 deletions src/AsyncEventSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,24 +368,27 @@ void AsyncEventSource::_addClient(AsyncEventSourceClient *client) {
if (!client) {
return;
}

if (_connectcb) {
_connectcb(client);
}

#ifdef ESP32
std::lock_guard<std::recursive_mutex> lock(_client_queue_lock);
#endif

_clients.emplace_back(client);
if (_connectcb) {
_connectcb(client);
}

_adjust_inflight_window();
}

void AsyncEventSource::_handleDisconnect(AsyncEventSourceClient *client) {
#ifdef ESP32
std::lock_guard<std::recursive_mutex> lock(_client_queue_lock);
#endif
if (_disconnectcb) {
_disconnectcb(client);
}
#ifdef ESP32
std::lock_guard<std::recursive_mutex> lock(_client_queue_lock);
#endif
for (auto i = _clients.begin(); i != _clients.end(); ++i) {
if (i->get() == client) {
_clients.erase(i);
Expand Down
4 changes: 3 additions & 1 deletion src/AsyncJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <ESPAsyncWebServer.h>
#include "ChunkPrint.h"

#include <utility>

#if ASYNC_JSON_SUPPORT == 1

#if ARDUINOJSON_VERSION_MAJOR == 6
Expand Down Expand Up @@ -104,7 +106,7 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
#endif

void setMethod(WebRequestMethodComposite method) {
_method = method;
_method = std::move(method);
}
void setMaxContentLength(int maxContentLength) {
_maxContentLength = maxContentLength;
Expand Down
11 changes: 9 additions & 2 deletions src/ESPAsyncWebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,26 @@ class WebRequestMethodComposite {
constexpr WebRequestMethodComposite(uint32_t m) : mask(m){};

public:
// Default constructor: by default, matches nothing
constexpr WebRequestMethodComposite() : mask(0){};

// Constructor: allows implicit conversion from WebRequestMethod
constexpr WebRequestMethodComposite(WebRequestMethod m) : mask(static_cast<uint32_t>(m)){};

// Combine composites
constexpr inline WebRequestMethodComposite operator|(WebRequestMethodComposite r) const {
constexpr inline WebRequestMethodComposite operator|(const WebRequestMethodComposite &r) const {
return WebRequestMethodComposite(mask | r.mask);
};

// == operator for composite
constexpr inline bool operator==(WebRequestMethodComposite r) const {
constexpr inline bool operator==(const WebRequestMethodComposite &r) const {
return mask == r.mask;
};

constexpr inline bool operator!=(const WebRequestMethodComposite &r) const {
return mask != r.mask;
};

// Check for a match
constexpr inline bool matches(WebRequestMethod m) const {
return mask & static_cast<uint32_t>(m);
Expand Down
3 changes: 2 additions & 1 deletion src/WebHandlerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <time.h>

#include <string>
#include <utility>

class AsyncStaticWebHandler : public AsyncWebHandler {
using File = fs::File;
Expand Down Expand Up @@ -65,7 +66,7 @@ class AsyncCallbackWebHandler : public AsyncWebHandler {
AsyncCallbackWebHandler() : _uri(), _method(AsyncWebRequestMethod::HTTP_ALL), _onRequest(NULL), _onUpload(NULL), _onBody(NULL), _isRegex(false) {}
void setUri(AsyncURIMatcher uri);
void setMethod(WebRequestMethodComposite method) {
_method = method;
_method = std::move(method);
}
void onRequest(ArRequestHandlerFunction fn) {
_onRequest = fn;
Expand Down
4 changes: 2 additions & 2 deletions src/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ AsyncCallbackWebHandler &AsyncWebServer::on(
) {
AsyncCallbackWebHandler *handler = new AsyncCallbackWebHandler();
handler->setUri(std::move(uri));
handler->setMethod(method);
handler->setMethod(std::move(method));
handler->onRequest(onRequest);
handler->onUpload(onUpload);
handler->onBody(onBody);
Expand All @@ -169,7 +169,7 @@ AsyncCallbackWebHandler &AsyncWebServer::on(
#if ASYNC_JSON_SUPPORT == 1
AsyncCallbackJsonWebHandler &AsyncWebServer::on(AsyncURIMatcher uri, WebRequestMethodComposite method, ArJsonRequestHandlerFunction onBody) {
AsyncCallbackJsonWebHandler *handler = new AsyncCallbackJsonWebHandler(std::move(uri), onBody);
handler->setMethod(method);
handler->setMethod(std::move(method));
addHandler(handler);
return *handler;
}
Expand Down
Loading