Skip to content

AsyncRouter #176

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

AsyncRouter #176

wants to merge 4 commits into from

Conversation

zekageri
Copy link

No description provided.

AsyncRouter::~AsyncRouter() {
for (AsyncCallbackWebHandler* handler : _handlers) {
_server->removeHandler(handler);
delete handler;
Copy link
Member

Choose a reason for hiding this comment

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

What is the handler is a static class instance created by the user ?

@mathieucarbou mathieucarbou marked this pull request as draft May 11, 2025 22:49
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces the AsyncRouter feature to modularize route handling in the AsyncWebServer. Key changes include:

  • Adding overloaded addRouter methods (for unique_ptr and raw pointer) and corresponding removeRouter functionality.
  • Creating a new AsyncRouter class with its header and implementation.
  • Providing an example usage in router.ino.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/WebServer.cpp Added AsyncRouter add and remove methods to AsyncWebServer.
src/ESPAsyncWebServer.h Declared AsyncRouter methods and included AsyncRouter.h with updated documentation.
src/AsyncRouter.h Introduced the AsyncRouter class interface.
src/AsyncRouter.cpp Implemented the AsyncRouter class including route handling and middleware addition.
examples/Router/router.ino Provided example usage demonstrating how to use the new AsyncRouter functionality.
Comments suppressed due to low confidence (1)

src/AsyncRouter.cpp:35

  • The method name 'addMidleware' appears to contain a typo. Consider renaming it to 'addMiddleware' to improve clarity.
void AsyncRouter::addMidleware(AsyncMiddleware* middleware) {

Comment on lines +1134 to +1138
* a deep copy of the pointer object will be created,
* it is up to user to manage further lifetime of the object in argument
*
* @param router pointer to router object to copy setting from
* @return AsyncRouter& reference to a newly created router
Copy link
Preview

Copilot AI May 11, 2025

Choose a reason for hiding this comment

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

The documentation for addRouter(unique_ptr) mentions that a deep copy of the router object will be created, but the implementation instead transfers ownership. Please update the comment to accurately reflect the behavior.

Suggested change
* a deep copy of the pointer object will be created,
* it is up to user to manage further lifetime of the object in argument
*
* @param router pointer to router object to copy setting from
* @return AsyncRouter& reference to a newly created router
* Transfers ownership of the router object to the method.
* The caller is no longer responsible for managing the lifetime of the object.
*
* @param router unique pointer to the router object to be added
* @return AsyncRouter& reference to the added router

Copilot uses AI. Check for mistakes.

Comment on lines +1174 to +1175
* this will NOT deallocate pointed object itself, internal router with same path will be removed if any
* it's a compat method, better use `removeRouter(const char* path)`
Copy link
Preview

Copilot AI May 11, 2025

Choose a reason for hiding this comment

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

The comment states that removeRouter(AsyncRouter* router) will NOT deallocate the pointed object, yet the implementation removes the unique_ptr from the container (which will deallocate the object). Clarify the intended ownership and deallocation behavior in the documentation.

Suggested change
* this will NOT deallocate pointed object itself, internal router with same path will be removed if any
* it's a compat method, better use `removeRouter(const char* path)`
* this will deallocate the pointed object, as the internal container uses unique_ptr for ownership.
* It's a compat method, better use `removeRouter(const char* path)`

Copilot uses AI. Check for mistakes.

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.

2 participants