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

Pass String by const reference [3.0] #6583

Merged
merged 2 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions libraries/ESP8266WebServer/src/detail/RequestHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class RequestHandler {
using WebServerType = ESP8266WebServerTemplate<ServerType>;
public:
virtual ~RequestHandler() { }
virtual bool canHandle(HTTPMethod method, String uri) { (void) method; (void) uri; return false; }
virtual bool canUpload(String uri) { (void) uri; return false; }
virtual bool handle(WebServerType& server, HTTPMethod requestMethod, String requestUri) { (void) server; (void) requestMethod; (void) requestUri; return false; }
virtual void upload(WebServerType& server, String requestUri, HTTPUpload& upload) { (void) server; (void) requestUri; (void) upload; }
virtual bool canHandle(HTTPMethod method, const String& uri) { (void) method; (void) uri; return false; }
virtual bool canUpload(const String& uri) { (void) uri; return false; }
virtual bool handle(WebServerType& server, HTTPMethod requestMethod, const String& requestUri) { (void) server; (void) requestMethod; (void) requestUri; return false; }
virtual void upload(WebServerType& server, const String& requestUri, HTTPUpload& upload) { (void) server; (void) requestUri; (void) upload; }

RequestHandler<ServerType>* next() { return _next; }
void next(RequestHandler<ServerType>* r) { _next = r; }
Expand Down
14 changes: 8 additions & 6 deletions libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ class FunctionRequestHandler : public RequestHandler<ServerType> {
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, RequestHandler<ServerType>::pathArgs);
}

bool canUpload(String requestUri) override {
bool canUpload(const String& requestUri) override {
if (!_ufn || !canHandle(HTTP_POST, requestUri))
return false;

return true;
}

bool handle(WebServerType& server, HTTPMethod requestMethod, String requestUri) override {
bool handle(WebServerType& server, HTTPMethod requestMethod, const String& requestUri) override {
(void) server;
if (!canHandle(requestMethod, requestUri))
return false;
Expand All @@ -48,7 +48,7 @@ class FunctionRequestHandler : public RequestHandler<ServerType> {
return true;
}

void upload(WebServerType& server, String requestUri, HTTPUpload& upload) override {
void upload(WebServerType& server, const String& requestUri, HTTPUpload& upload) override {
(void) server;
(void) upload;
if (canUpload(requestUri))
Expand Down Expand Up @@ -85,7 +85,7 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
_baseUriLength = _uri.length();
}

bool canHandle(HTTPMethod requestMethod, String requestUri) override {
bool canHandle(HTTPMethod requestMethod, const String& requestUri) override {
if ((requestMethod != HTTP_GET) && (requestMethod != HTTP_HEAD))
return false;

Expand All @@ -95,7 +95,9 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
return true;
}

bool handle(WebServerType& server, HTTPMethod requestMethod, String requestUri) override {
bool handle(WebServerType& server, HTTPMethod requestMethod, const String& __requestUri) override {
String requestUri(__requestUri);

Copy link
Collaborator

Choose a reason for hiding this comment

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

This String copy can be handled differently in a further fixing commit.

if (!canHandle(requestMethod, requestUri))
return false;

Expand Down