1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-26 07:02:15 +03:00

Add Uri with support for regexUri and globUri (#6696)

* Add path args

* Add example

* Update code format

* Add missing include

* Fix codestyle and unsigned int

* fix unsigned int

* Remove tabs

* use vector<>.resize

* rename j to requestUriIndex

* using assert checking the path argument index

* Add missing include "assert.h"

* The order no longer matters.
Path arguments may not contain the value '/'
Updated the example

* make pathArg return a const

* Update PathArgServer.ino

fix trailing space

* const String&

* Add regex support

* Fix to match templating

* Add Uri with support for staticUri, regexUri and globUri

* Update example

* Add deconstructor to remove _uri pointer

* Add newline to end of files

* Suppress gcc warnings (unused params)

* Replace regex with regex.h

* Use the standard STASSID/PSK settings for example

Make the example match the existing examples which allow setting
the SSID/PSK in the local platform.txt file.

* Use 115.2Kbaud for example, match others

Co-authored-by: david gauchard <gauchard@laas.fr>
Co-authored-by: Earle F. Philhower, III <earlephilhower@yahoo.com>
This commit is contained in:
Bob
2020-02-22 20:51:47 +01:00
committed by GitHub
parent a40663b65f
commit 4eca62cb53
9 changed files with 251 additions and 13 deletions

View File

@ -2,6 +2,8 @@
#define REQUESTHANDLER_H
#include <ESP8266WebServer.h>
#include <vector>
#include <assert.h>
template<typename ServerType>
class RequestHandler {
@ -18,6 +20,15 @@ public:
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

View File

@ -5,6 +5,7 @@
#include "RequestHandler.h"
#include "mimetable.h"
#include "WString.h"
#include "Uri.h"
using namespace mime;
@ -12,22 +13,23 @@ template<typename ServerType>
class FunctionRequestHandler : public RequestHandler<ServerType> {
using WebServerType = ESP8266WebServerTemplate<ServerType>;
public:
FunctionRequestHandler(typename WebServerType::THandlerFunction fn, typename WebServerType::THandlerFunction ufn, const String &uri, HTTPMethod method)
FunctionRequestHandler(typename WebServerType::THandlerFunction fn, typename WebServerType::THandlerFunction ufn, const Uri &uri, HTTPMethod method)
: _fn(fn)
, _ufn(ufn)
, _uri(uri)
, _uri(uri.clone())
, _method(method)
{
}
~FunctionRequestHandler() {
delete _uri;
}
bool canHandle(HTTPMethod requestMethod, String requestUri) override {
if (_method != HTTP_ANY && _method != requestMethod)
return false;
if (requestUri != _uri)
return false;
return true;
return _uri->canHandle(requestUri, RequestHandler<ServerType>::pathArgs);
}
bool canUpload(String requestUri) override {
@ -56,7 +58,7 @@ public:
protected:
typename WebServerType::THandlerFunction _fn;
typename WebServerType::THandlerFunction _ufn;
String _uri;
Uri *_uri;
HTTPMethod _method;
};