Skip to content

Commit

Permalink
Required '/' at beginning of routes.
Browse files Browse the repository at this point in the history
  • Loading branch information
benh committed Jun 24, 2012
1 parent a216d45 commit 9ff9dd5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions include/process/process.hpp
Expand Up @@ -122,15 +122,19 @@ class ProcessBase : public EventVisitor
HttpRequestHandler;

// Setup a handler for an HTTP request.
void route(
bool route(
const std::string& name,
const HttpRequestHandler& handler)
{
handlers.http[name] = handler;
if (name.find('/') != 0) {
return false;
}
handlers.http[name.substr(1)] = handler;
return true;
}

template <typename T>
void route(
bool route(
const std::string& name,
Future<HttpResponse> (T::*method)(const HttpRequest&))
{
Expand All @@ -140,7 +144,7 @@ class ProcessBase : public EventVisitor
HttpRequestHandler handler =
std::tr1::bind(method, dynamic_cast<T*>(this),
std::tr1::placeholders::_1);
route(name, handler);
return route(name, handler);
}

// Provide the static asset(s) at the specified _absolute_ path for
Expand Down
2 changes: 1 addition & 1 deletion src/tests.cpp
Expand Up @@ -1006,7 +1006,7 @@ class HttpProcess : public Process<HttpProcess>
public:
HttpProcess()
{
route("handler", &HttpProcess::handler);
route("/handler", &HttpProcess::handler);
}

MOCK_METHOD1(handler, Future<HttpResponse>(const HttpRequest&));
Expand Down

0 comments on commit 9ff9dd5

Please sign in to comment.