Skip to content
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

webserver hook: allow to handle external http protocol #7459

Merged
merged 14 commits into from
Jul 28, 2020

Conversation

d-a-v
Copy link
Collaborator

@d-a-v d-a-v commented Jul 15, 2020

webserver.addHook() addition, allowing to handle external http protocols on the same port, at least like WebDAV and WebSocket.

Tested with ESPWebDAV branch v2.

A hook function can use URI and http method to check if it would handle the http request.
There are 4 possible return values:

  • CLIENT_REQUEST_CAN_CONTINUE
    Hook function is not interested
  • CLIENT_REQUEST_IS_HANDLED
    Hook function took and handled the current http request, webserver must skip it but can handle the next request
  • CLIENT_MUST_STOP
    Issue with http protocol, or general malfunction, or connection is done. Connection should be closed.
  • CLIENT_IS_GIVEN
    The tcp connection has been given to someone else, it must not be closed neither anymore handled
    (this is typically for websockets)

Example of a hook function: call on webserver, function itself.

Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally nice. I like the lambda work in addHook!

It's use is a little obscure, however, and we don't have any docs for this class. Would it be possible to use the hook in an example somehow, so people can see it in action w/o using the external webDAV class?

libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h Outdated Show resolved Hide resolved
libraries/ESP8266WebServer/src/ESP8266WebServer.h Outdated Show resolved Hide resolved
libraries/ESP8266WebServer/src/ESP8266WebServer.h Outdated Show resolved Hide resolved
libraries/ESP8266WebServer/src/ESP8266WebServer.h Outdated Show resolved Hide resolved
@d-a-v
Copy link
Collaborator Author

d-a-v commented Jul 17, 2020

@earlephilhower I addressed your review, I still need to check whether lambdas/functionals are in flash (not iram) thanks to your snippet

    uint32_t addr;
    __asm__ ("movi %0, ." : "=r" (addr) : : );
    // 401x:iram 402x:flash
    Serial.printf("%08x\n", addr);

@d-a-v
Copy link
Collaborator Author

d-a-v commented Jul 17, 2020

Example is provided in Helloserver.cpp.

Comment on lines 93 to 96
(void)method;
(void)url;
(void)client;
(void)contentType;
Copy link
Collaborator

@mcspr mcspr Jul 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style nitpick - by omitting argument name in the signature, there would be no need for these 4 lines.
There is also [[maybe_unused]] / [[gnu::unused]] for local declaration, since now we use c++17. But that one is mostly for variables

Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants