Skip to content

Commit 9a75f53

Browse files
committed
Some code cleanups
1 parent 40f886c commit 9a75f53

File tree

6 files changed

+43
-22
lines changed

6 files changed

+43
-22
lines changed

examples/HTTPMethodsWithArduino/HTTPMethodsWithArduino.ino

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ void setup() {
101101

102102
server.begin();
103103

104-
WebRequestMethodComposite composite1 = WebRequestMethod::HTTP_GET | WebRequestMethod::HTTP_POST;
105-
WebRequestMethodComposite composite2 = WebRequestMethod::HTTP_GET | WebRequestMethod::HTTP_POST;
106-
WebRequestMethodComposite composite3 = WebRequestMethod::HTTP_HEAD | WebRequestMethod::HTTP_OPTIONS;
104+
WebRequestMethodComposite composite1 = AsyncWebRequestMethod::HTTP_GET | AsyncWebRequestMethod::HTTP_POST;
105+
WebRequestMethodComposite composite2 = AsyncWebRequestMethod::HTTP_GET | AsyncWebRequestMethod::HTTP_POST;
106+
WebRequestMethodComposite composite3 = AsyncWebRequestMethod::HTTP_HEAD | AsyncWebRequestMethod::HTTP_OPTIONS;
107107
WebRequestMethodComposite composite4 = composite3;
108-
WebRequestMethodComposite composite5 = WebRequestMethod::HTTP_GET;
108+
WebRequestMethodComposite composite5 = AsyncWebRequestMethod::HTTP_GET;
109109

110-
assert(composite1.matches(WebRequestMethod::HTTP_GET));
111-
assert(composite1.matches(WebRequestMethod::HTTP_POST));
112-
assert(!composite1.matches(WebRequestMethod::HTTP_HEAD));
113-
assert(!composite3.matches(WebRequestMethod::HTTP_GET));
110+
assert(composite1.matches(AsyncWebRequestMethod::HTTP_GET));
111+
assert(composite1.matches(AsyncWebRequestMethod::HTTP_POST));
112+
assert(!composite1.matches(AsyncWebRequestMethod::HTTP_HEAD));
113+
assert(!composite3.matches(AsyncWebRequestMethod::HTTP_GET));
114114

115115
assert(composite1 == composite2);
116116
assert(composite3 == composite4);

examples/HTTPMethodsWithESPIDF/HTTPMethodsWithESPIDF.ino

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ void setup() {
104104

105105
server.begin();
106106

107-
WebRequestMethodComposite composite1 = WebRequestMethod::HTTP_GET | WebRequestMethod::HTTP_POST;
108-
WebRequestMethodComposite composite2 = WebRequestMethod::HTTP_GET | WebRequestMethod::HTTP_POST;
109-
WebRequestMethodComposite composite3 = WebRequestMethod::HTTP_HEAD | WebRequestMethod::HTTP_OPTIONS;
107+
WebRequestMethodComposite composite1 = AsyncWebRequestMethod::HTTP_GET | AsyncWebRequestMethod::HTTP_POST;
108+
WebRequestMethodComposite composite2 = AsyncWebRequestMethod::HTTP_GET | AsyncWebRequestMethod::HTTP_POST;
109+
WebRequestMethodComposite composite3 = AsyncWebRequestMethod::HTTP_HEAD | AsyncWebRequestMethod::HTTP_OPTIONS;
110110
WebRequestMethodComposite composite4 = composite3;
111-
WebRequestMethodComposite composite5 = WebRequestMethod::HTTP_GET;
111+
WebRequestMethodComposite composite5 = AsyncWebRequestMethod::HTTP_GET;
112112

113-
assert(composite1.matches(WebRequestMethod::HTTP_GET));
114-
assert(composite1.matches(WebRequestMethod::HTTP_POST));
115-
assert(!composite1.matches(WebRequestMethod::HTTP_HEAD));
116-
assert(!composite3.matches(WebRequestMethod::HTTP_GET));
113+
assert(composite1.matches(AsyncWebRequestMethod::HTTP_GET));
114+
assert(composite1.matches(AsyncWebRequestMethod::HTTP_POST));
115+
assert(!composite1.matches(AsyncWebRequestMethod::HTTP_HEAD));
116+
assert(!composite3.matches(AsyncWebRequestMethod::HTTP_GET));
117117

118118
assert(composite1 == composite2);
119119
assert(composite3 == composite4);

src/AsyncJson.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <ESPAsyncWebServer.h>
77
#include "ChunkPrint.h"
88

9+
#include <utility>
10+
911
#if ASYNC_JSON_SUPPORT == 1
1012

1113
#if ARDUINOJSON_VERSION_MAJOR == 6
@@ -104,7 +106,7 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
104106
#endif
105107

106108
void setMethod(WebRequestMethodComposite method) {
107-
_method = method;
109+
_method = std::move(method);
108110
}
109111
void setMaxContentLength(int maxContentLength) {
110112
_maxContentLength = maxContentLength;

src/ESPAsyncWebServer.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,37 @@ class WebRequestMethodComposite {
154154
constexpr WebRequestMethodComposite(uint32_t m) : mask(m){};
155155

156156
public:
157+
WebRequestMethodComposite(const WebRequestMethodComposite &other) = default;
158+
WebRequestMethodComposite(WebRequestMethodComposite &&other) = default;
159+
157160
// Constructor: allows implicit conversion from WebRequestMethod
158161
constexpr WebRequestMethodComposite(WebRequestMethod m) : mask(static_cast<uint32_t>(m)){};
159162

160163
// Combine composites
161-
constexpr inline WebRequestMethodComposite operator|(WebRequestMethodComposite r) const {
164+
constexpr inline WebRequestMethodComposite operator|(const WebRequestMethodComposite &r) const {
162165
return WebRequestMethodComposite(mask | r.mask);
163166
};
164167

168+
WebRequestMethodComposite &operator=(const WebRequestMethodComposite &r) {
169+
mask = r.mask;
170+
return *this;
171+
}
172+
173+
WebRequestMethodComposite &operator=(WebRequestMethodComposite &&r) {
174+
mask = r.mask;
175+
r.mask = 0;
176+
return *this;
177+
}
178+
165179
// == operator for composite
166-
constexpr inline bool operator==(WebRequestMethodComposite r) const {
180+
constexpr inline bool operator==(const WebRequestMethodComposite &r) const {
167181
return mask == r.mask;
168182
};
169183

184+
constexpr inline bool operator!=(const WebRequestMethodComposite &r) const {
185+
return mask != r.mask;
186+
};
187+
170188
// Check for a match
171189
constexpr inline bool matches(WebRequestMethod m) const {
172190
return mask & static_cast<uint32_t>(m);

src/WebHandlerImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <time.h>
88

99
#include <string>
10+
#include <utility>
1011

1112
class AsyncStaticWebHandler : public AsyncWebHandler {
1213
using File = fs::File;
@@ -65,7 +66,7 @@ class AsyncCallbackWebHandler : public AsyncWebHandler {
6566
AsyncCallbackWebHandler() : _uri(), _method(AsyncWebRequestMethod::HTTP_ALL), _onRequest(NULL), _onUpload(NULL), _onBody(NULL), _isRegex(false) {}
6667
void setUri(AsyncURIMatcher uri);
6768
void setMethod(WebRequestMethodComposite method) {
68-
_method = method;
69+
_method = std::move(method);
6970
}
7071
void onRequest(ArRequestHandlerFunction fn) {
7172
_onRequest = fn;

src/WebServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ AsyncCallbackWebHandler &AsyncWebServer::on(
158158
) {
159159
AsyncCallbackWebHandler *handler = new AsyncCallbackWebHandler();
160160
handler->setUri(std::move(uri));
161-
handler->setMethod(method);
161+
handler->setMethod(std::move(method));
162162
handler->onRequest(onRequest);
163163
handler->onUpload(onUpload);
164164
handler->onBody(onBody);
@@ -169,7 +169,7 @@ AsyncCallbackWebHandler &AsyncWebServer::on(
169169
#if ASYNC_JSON_SUPPORT == 1
170170
AsyncCallbackJsonWebHandler &AsyncWebServer::on(AsyncURIMatcher uri, WebRequestMethodComposite method, ArJsonRequestHandlerFunction onBody) {
171171
AsyncCallbackJsonWebHandler *handler = new AsyncCallbackJsonWebHandler(std::move(uri), onBody);
172-
handler->setMethod(method);
172+
handler->setMethod(std::move(method));
173173
addHandler(handler);
174174
return *handler;
175175
}

0 commit comments

Comments
 (0)