mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-24 19:42:27 +03:00
Passing String by value means a full copy-constructor/temporary string creation which is slightly inefficient. Avoid that by using const references.
35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
#ifndef REQUESTHANDLER_H
|
|
#define REQUESTHANDLER_H
|
|
|
|
#include <ESP8266WebServer.h>
|
|
#include <vector>
|
|
#include <assert.h>
|
|
|
|
template<typename ServerType>
|
|
class RequestHandler {
|
|
using WebServerType = ESP8266WebServerTemplate<ServerType>;
|
|
public:
|
|
virtual ~RequestHandler() { }
|
|
virtual bool canHandle(HTTPMethod method, const String& uri) { (void) method; (void) uri; return false; }
|
|
virtual bool canUpload(const String& uri) { (void) uri; return false; }
|
|
virtual bool handle(WebServerType& server, HTTPMethod requestMethod, const String& requestUri) { (void) server; (void) requestMethod; (void) requestUri; return false; }
|
|
virtual void upload(WebServerType& server, const String& requestUri, HTTPUpload& upload) { (void) server; (void) requestUri; (void) upload; }
|
|
|
|
RequestHandler<ServerType>* next() { return _next; }
|
|
void next(RequestHandler<ServerType>* r) { _next = r; }
|
|
|
|
private:
|
|
RequestHandler<ServerType>* _next = nullptr;
|
|
|
|
protected:
|
|
std::vector<String> pathArgs;
|
|
|
|
public:
|
|
const String& pathArg(unsigned int i) {
|
|
assert(i < pathArgs.size());
|
|
return pathArgs[i];
|
|
}
|
|
};
|
|
|
|
#endif //REQUESTHANDLER_H
|