-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Reduce copy of Strings in WebServer RequestHandler #10345
Merged
me-no-dev
merged 2 commits into
espressif:master
from
TD-er:RequestHandler_reduce_string_copy
Sep 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,55 +21,55 @@ class FunctionRequestHandler : public RequestHandler { | |
delete _uri; | ||
} | ||
|
||
bool canHandle(HTTPMethod requestMethod, String requestUri) override { | ||
bool canHandle(HTTPMethod requestMethod, const String& requestUri) override { | ||
if (_method != HTTP_ANY && _method != requestMethod) { | ||
return false; | ||
} | ||
|
||
return _uri->canHandle(requestUri, pathArgs); | ||
} | ||
|
||
bool canUpload(String requestUri) override { | ||
bool canUpload(const String& requestUri) override { | ||
if (!_ufn || !canHandle(HTTP_POST, requestUri)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool canRaw(String requestUri) override { | ||
bool canRaw(const String& requestUri) override { | ||
if (!_ufn || _method == HTTP_GET) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool canHandle(WebServer &server, HTTPMethod requestMethod, String requestUri) override { | ||
bool canHandle(WebServer &server, HTTPMethod requestMethod, const String& requestUri) override { | ||
if (_method != HTTP_ANY && _method != requestMethod) { | ||
return false; | ||
} | ||
|
||
return _uri->canHandle(requestUri, pathArgs) && (_filter != NULL ? _filter(server) : true); | ||
} | ||
|
||
bool canUpload(WebServer &server, String requestUri) override { | ||
bool canUpload(WebServer &server, const String& requestUri) override { | ||
if (!_ufn || !canHandle(server, HTTP_POST, requestUri)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool canRaw(WebServer &server, String requestUri) override { | ||
bool canRaw(WebServer &server, const String& requestUri) override { | ||
if (!_ufn || _method == HTTP_GET || (_filter != NULL ? _filter(server) == false : false)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool handle(WebServer &server, HTTPMethod requestMethod, String requestUri) override { | ||
bool handle(WebServer &server, HTTPMethod requestMethod, const String& requestUri) override { | ||
if (!canHandle(server, requestMethod, requestUri)) { | ||
return false; | ||
} | ||
|
@@ -78,14 +78,14 @@ class FunctionRequestHandler : public RequestHandler { | |
return true; | ||
} | ||
|
||
void upload(WebServer &server, String requestUri, HTTPUpload &upload) override { | ||
void upload(WebServer &server, const String& requestUri, HTTPUpload &upload) override { | ||
(void)upload; | ||
if (canUpload(server, requestUri)) { | ||
_ufn(); | ||
} | ||
} | ||
|
||
void raw(WebServer &server, String requestUri, HTTPRaw &raw) override { | ||
void raw(WebServer &server, const String& requestUri, HTTPRaw &raw) override { | ||
(void)raw; | ||
if (canRaw(server, requestUri)) { | ||
_ufn(); | ||
|
@@ -118,7 +118,7 @@ class StaticRequestHandler : public RequestHandler { | |
_baseUriLength = _uri.length(); | ||
} | ||
|
||
bool canHandle(HTTPMethod requestMethod, String requestUri) override { | ||
bool canHandle(HTTPMethod requestMethod, const String& requestUri) override { | ||
if (requestMethod != HTTP_GET) { | ||
return false; | ||
} | ||
|
@@ -130,7 +130,7 @@ class StaticRequestHandler : public RequestHandler { | |
return true; | ||
} | ||
|
||
bool canHandle(WebServer &server, HTTPMethod requestMethod, String requestUri) override { | ||
bool canHandle(WebServer &server, HTTPMethod requestMethod, const String& requestUri) override { | ||
if (requestMethod != HTTP_GET) { | ||
return false; | ||
} | ||
|
@@ -146,21 +146,20 @@ class StaticRequestHandler : public RequestHandler { | |
return true; | ||
} | ||
|
||
bool handle(WebServer &server, HTTPMethod requestMethod, String requestUri) override { | ||
bool handle(WebServer &server, HTTPMethod requestMethod, const String& requestUri) override { | ||
if (!canHandle(server, requestMethod, requestUri)) { | ||
return false; | ||
} | ||
|
||
log_v("StaticRequestHandler::handle: request=%s _uri=%s\r\n", requestUri.c_str(), _uri.c_str()); | ||
|
||
String path(_path); | ||
String eTagCode; | ||
|
||
if (!_isFile) { | ||
// Base URI doesn't point to a file. | ||
// If a directory is requested, look for index file. | ||
if (requestUri.endsWith("/")) { | ||
requestUri += "index.htm"; | ||
return handle(server, requestMethod, String(requestUri + "index.htm")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we can keep the |
||
} | ||
|
||
// Append whatever follows this URI in request to get the file path. | ||
|
@@ -184,6 +183,8 @@ class StaticRequestHandler : public RequestHandler { | |
return false; | ||
} | ||
|
||
String eTagCode; | ||
|
||
if (server._eTagEnabled) { | ||
if (server._eTagFunction) { | ||
eTagCode = (server._eTagFunction)(_fs, path); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving it changes nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Less allocated on the stack when it returns early (e.g. due to the added single recursive call you asked about in the previous comment.