8000 webserver hook: allow to handle external http protocol by d-a-v · Pull Request #7459 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

webserver hook: allow to handle external http protocol #7459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jul 28, 2020
Prev Previous commit
Next Next commit
nothing against Hungarians
  • Loading branch information
d-a-v committed Jul 17, 2020
commit b55febab61b340a8a77fdd4933d4bd0fbb5fe63d
15 changes: 8 additions & 7 deletions libraries/ESP8266WebServer/src/ESP8266WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
#include "detail/mimetable.h"
#include "Uri.h"

//#define DEBUG_ESP_HTTP_SERVER
#define DEBUG_ESP_HTTP_SERVER

#ifdef DEBUG_ESP_HTTP_SERVER
#ifdef DEBUG_ESP_PORT
#define DBGWS(f,...) do { DEBUG_ESP_PORT.printf(PSTR(f), ##__VA_ARGS__); } while (0)
#else
#define DBGWS(f,...) do { Serial.printf(F(f), ##__VA_ARGS__); } while (0)
#define DBGWS(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
#endif
#else
#define DBGWS(x...) do { (void)0; } while (0)
Expand Down Expand Up @@ -93,9 +93,9 @@ class ESP8266WebServerTemplate
using ClientType = typename ServerType::ClientType;
using RequestHandlerType = RequestHandler<ServerType>;
using WebServerType = ESP8266WebServerTemplate<ServerType>;
using ContentType_f = std::function<String(const String&)>;
enum ClientFuture_e { CLIENT_REQUEST_CAN_CONTINUE, CLIENT_REQUEST_IS_HANDLED, CLIENT_MUST_STOP, CLIENT_IS_GIVEN };
using Hook_f = std::function<ClientFuture_e(const String& method, const String& url, WiFiClient* client, ContentType_f contentType)>;
typedef String (*ContentTypeFunction) (const String&);
using HookFunction = std::function<ClientFuture_e(const String& method, const String& url, WiFiClient* client, ContentTypeFunction contentType)>;

void begin();
void begin(uint16_t port);
Expand Down Expand Up @@ -208,10 +208,11 @@ class ESP8266WebServerTemplate

static String responseCodeToString(const int code);

void addHook (Hook_f hook) {
void addHook (HookFunction hook) {
DBGWS("addHook: @=%p\n", hook);
if (_hook) {
auto previousHook = _hook;
_hook = [previousHook, hook](const String& method, const String& url, WiFiClient* client, ContentType_f contentType) {
_hook = [previousHook, hook](const String& method, const String& url, WiFiClient* client, ContentTypeFunction contentType) {
auto whatNow = previousHook(method, url, client, contentType);
if (whatNow == CLIENT_REQUEST_CAN_CONTINUE)
return hook(method, url, client, contentType);
Expand Down Expand Up @@ -282,7 +283,7 @@ class ESP8266WebServerTemplate
String _sopaque;
String _srealm; // Store the Auth realm between Calls

Hook_f _hook;
HookFunction _hook;
};


Expand Down
0