8000 More String moves · troyhacks/ESPAsyncWebServer@8b41e4f · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b41e4f

Browse files
committed
More String moves
Also lets us accept PROGMEM for function inputs.
1 parent ebf89cf commit 8b41e4f

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

src/ESPAsyncWebServer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,12 @@ class AsyncWebServer {
421421
AsyncWebHandler& addHandler(AsyncWebHandler* handler);
422422
bool removeHandler(AsyncWebHandler* handler);
423423

424-
AsyncCallbackWebHandler& on(const char* uri, ArRequestHandlerFunction onRequest);
425-
AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest);
426-
AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload);
427-
AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload, ArBodyHandlerFunction onBody);
424+
AsyncCallbackWebHandler& on(String uri, ArRequestHandlerFunction onRequest);
425+
AsyncCallbackWebHandler& on(String uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest);
426+
AsyncCallbackWebHandler& on(String uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload);
427+
AsyncCallbackWebHandler& on(String uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload, ArBodyHandlerFunction onBody);
428428

429-
AsyncStaticWebHandler& serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_control = NULL);
429+
AsyncStaticWebHandler& serveStatic(String uri, fs::FS& fs, String path, const char* cache_control = NULL);
430430

431431
void onNotFound(ArRequestHandlerFunction fn); //called when handler is not assigned
432432
void onFileUpload(ArUploadHandlerFunction fn); //handle file uploads

src/WebHandlerImpl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AsyncStaticWebHandler: public AsyncWebHandler {
4848
bool _gzipFirst;
4949
uint8_t _gzipStats;
5050
public:
51-
AsyncStaticWebHandler(const char* uri, FS& fs, const char* path, const char* cache_control);
51+
AsyncStaticWebHandler(String uri, FS& fs, String path, const char* cache_control);
5252
virtual bool canHandle(AsyncWebServerRequest *request) override final;
5353
virtual void handleRequest(AsyncWebServerRequest *request) override final;
5454
AsyncStaticWebHandler& setIsDir(bool isDir);
@@ -74,9 +74,9 @@ class AsyncCallbackWebHandler: public AsyncWebHandler {
7474
bool _isRegex;
7575
public:
7676
AsyncCallbackWebHandler() : _uri(), _method(HTTP_ANY), _onRequest(NULL), _onUpload(NULL), _onBody(NULL), _isRegex(false) {}
77-
void setUri(const String& uri){
78-
_uri = uri;
79-
_isRegex = uri.startsWith("^") && uri.endsWith("$");
77+
void setUri(String uri){
78+
_uri = std::move(uri);
79+
_isRegex = _uri.startsWith("^") && _uri.endsWith("$");
8080
}
8181
void setMethod(WebRequestMethodComposite method){ _method = method; }
8282
void onRequest(ArRequestHandlerFunction fn){ _onRequest = fn; }

src/WebHandlers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include "ESPAsyncWebServer.h"
2222
#include "WebHandlerImpl.h"
2323

24-
AsyncStaticWebHandler::AsyncStaticWebHandler(const char* uri, FS& fs, const char* path, const char* cache_control)
25-
: _fs(fs), _uri(uri), _path(path), _default_file("index.htm"), _cache_control(cache_control), _last_modified(""), _callback(nullptr)
24+
AsyncStaticWebHandler::AsyncStaticWebHandler(String uri, FS& fs, String path, const char* cache_control)
25+
: _fs(fs), _uri(std::move(uri)), _path(std::move(path)), _default_file("index.htm"), _cache_control(cache_control), _last_modified(""), _callback(nullptr)
2626
{
2727
// Ensure leading '/'
2828
if (_uri.length() == 0 || _uri[0] != '/') _uri = "/" + _uri;

src/WebServer.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ void AsyncWebServer::_attachHandler(AsyncWebServerRequest *request){
128128
}
129129

130130

131-
AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload, ArBodyHandlerFunction onBody){
131+
AsyncCallbackWebHandler& AsyncWebServer::on(String uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload, ArBodyHandlerFunction onBody){
132132
AsyncCallbackWebHandler* handler = new AsyncCallbackWebHandler();
133-
handler->setUri(uri);
133+
handler->setUri(std::move(uri));
134134
handler->setMethod(method);
135135
handler->onRequest(onRequest);
136136
handler->onUpload(onUpload);
@@ -139,35 +139,35 @@ AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, WebRequestMethodCom
139139
return *handler;
140140
}
141141

142-
AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload){
142+
AsyncCallbackWebHandler& AsyncWebServer::on(String uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload){
143143
AsyncCallbackWebHandler* handler = new AsyncCallbackWebHandler();
144-
handler->setUri(uri);
144+
handler->setUri(std::move(uri));
145145
handler->setMethod(method);
146146
handler->onRequest(onRequest);
147147
handler->onUpload(onUpload);
148148
addHandler(handler);
149149
return *handler;
150150
}
151151

152-
AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest){
152+
AsyncCallbackWebHandler& AsyncWebServer::on(String uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest){
153153
AsyncCallbackWebHandler* handler = new AsyncCallbackWebHandler();
154-
handler->setUri(uri);
154+
handler->setUri(std::move(uri));
155155
handler->setMethod(method);
156156
handler->onRequest(onRequest);
157157
addHandler(handler);
158158
return *handler;
159159
}
160160

161-
AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, ArRequestHandlerFunction onRequest){
161+
AsyncCallbackWebHandler& AsyncWebServer::on(String uri, ArRequestHandlerFunction onRequest){
162162
AsyncCallbackWebHandler* handler = new AsyncCallbackWebHandler();
163-
handler->setUri(uri);
163+
handler->setUri(std::move(uri));
164164
handler->onRequest(onRequest);
165165
addHandler(handler);
166166
return *handler;
167167
}
168168

169-
AsyncStaticWebHandler& AsyncWebServer::serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_control){
170-
AsyncStaticWebHandler* handler = new AsyncStaticWebHandler(uri, fs, path, cache_control);
169+
AsyncStaticWebHandler& AsyncWebServer::serveStatic(String uri, fs::FS& fs, String path, const char* cache_control){
170+
AsyncStaticWebHandler* handler = new AsyncStaticWebHandler(std::move(uri), fs, std::move(path), cache_control);
171171
addHandler(handler);
172172
return *handler;
173173
}

0 commit comments

Comments
 (0)
0