Skip to content

Commit

Permalink
allow F() to be used for uri parameter (#2319)
Browse files Browse the repository at this point in the history
  • Loading branch information
everslick authored and igrr committed Jul 26, 2016
1 parent 7900132 commit 4dc4e75
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions libraries/ESP8266WebServer/src/ESP8266WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ void ESP8266WebServer::requestAuthentication(){
send(401);
}

void ESP8266WebServer::on(const char* uri, ESP8266WebServer::THandlerFunction handler) {
void ESP8266WebServer::on(const String &uri, ESP8266WebServer::THandlerFunction handler) {
on(uri, HTTP_ANY, handler);
}

void ESP8266WebServer::on(const char* uri, HTTPMethod method, ESP8266WebServer::THandlerFunction fn) {
void ESP8266WebServer::on(const String &uri, HTTPMethod method, ESP8266WebServer::THandlerFunction fn) {
on(uri, method, fn, _fileUploadHandler);
}

void ESP8266WebServer::on(const char* uri, HTTPMethod method, ESP8266WebServer::THandlerFunction fn, ESP8266WebServer::THandlerFunction ufn) {
void ESP8266WebServer::on(const String &uri, HTTPMethod method, ESP8266WebServer::THandlerFunction fn, ESP8266WebServer::THandlerFunction ufn) {
_addRequestHandler(new FunctionRequestHandler(fn, ufn, uri, method));
}

Expand Down
6 changes: 3 additions & 3 deletions libraries/ESP8266WebServer/src/ESP8266WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class ESP8266WebServer
void requestAuthentication();

typedef std::function<void(void)> THandlerFunction;
void on(const char* uri, THandlerFunction handler);
void on(const char* uri, HTTPMethod method, THandlerFunction fn);
void on(const char* uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn);
void on(const String &uri, THandlerFunction handler);
void on(const String &uri, HTTPMethod method, THandlerFunction fn);
void on(const String &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn);
void addHandler(RequestHandler* handler);
void serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_header = NULL );
void onNotFound(THandlerFunction fn); //called when handler is not assigned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class FunctionRequestHandler : public RequestHandler {
public:
FunctionRequestHandler(ESP8266WebServer::THandlerFunction fn, ESP8266WebServer::THandlerFunction ufn, const char* uri, HTTPMethod method)
FunctionRequestHandler(ESP8266WebServer::THandlerFunction fn, ESP8266WebServer::THandlerFunction ufn, const String &uri, HTTPMethod method)
: _fn(fn)
, _ufn(ufn)
, _uri(uri)
Expand Down

7 comments on commit 4dc4e75

@tablatronix
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this not made to be backward compatible ?

@devyte
Copy link
Collaborator

@devyte devyte commented on 4dc4e75 Aug 28, 2018

Choose a reason for hiding this comment

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

@tablatronix What is not backwards compatible?

@tablatronix
Copy link
Contributor

@tablatronix tablatronix commented on 4dc4e75 Aug 28, 2018

Choose a reason for hiding this comment

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

void on(const String &uri, THandlerFunction handler);
2.3 takes const char*
2.4 takes const String

makes handling <=2.4 difficult.

Any ideas how to handle this for both ?

@devyte
Copy link
Collaborator

@devyte devyte commented on 4dc4e75 Aug 29, 2018

Choose a reason for hiding this comment

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

Doesn't const char * automatically promote to String?

@LuchtwachtersDelft
Copy link

@LuchtwachtersDelft LuchtwachtersDelft commented on 4dc4e75 Sep 7, 2018

Choose a reason for hiding this comment

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

Is re-adding void on(const char* uri, THandlerFunction handler); out of the question?

@tablatronix
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't const char * automatically promote to String?

perhaps but how does one use progmem in that case? flashstringhelper does not cast to c str afaik.

@tablatronix
Copy link
Contributor

@tablatronix tablatronix commented on 4dc4e75 Sep 7, 2018

Choose a reason for hiding this comment

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

I think I can do
server->on(String(FPSTR(whatnot))).c_str(),...)
For both verisons, thanks for that tip.

Please sign in to comment.