Make all http routes move-only
This commit is contained in:
@@ -223,58 +223,58 @@ public:
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplatedApp &&get(std::string pattern, std::function<void(HttpResponse<SSL> *, HttpRequest *)> handler) {
|
TemplatedApp &&get(std::string pattern, fu2::unique_function<void(HttpResponse<SSL> *, HttpRequest *)> &&handler) {
|
||||||
httpContext->onHttp("get", pattern, handler);
|
httpContext->onHttp("get", pattern, std::move(handler));
|
||||||
return std::move(*this);
|
return std::move(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplatedApp &&post(std::string pattern, std::function<void(HttpResponse<SSL> *, HttpRequest *)> handler) {
|
TemplatedApp &&post(std::string pattern, fu2::unique_function<void(HttpResponse<SSL> *, HttpRequest *)> &&handler) {
|
||||||
httpContext->onHttp("post", pattern, handler);
|
httpContext->onHttp("post", pattern, std::move(handler));
|
||||||
return std::move(*this);
|
return std::move(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplatedApp &&options(std::string pattern, std::function<void(HttpResponse<SSL> *, HttpRequest *)> handler) {
|
TemplatedApp &&options(std::string pattern, fu2::unique_function<void(HttpResponse<SSL> *, HttpRequest *)> &&handler) {
|
||||||
httpContext->onHttp("options", pattern, handler);
|
httpContext->onHttp("options", pattern, std::move(handler));
|
||||||
return std::move(*this);
|
return std::move(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplatedApp &&del(std::string pattern, std::function<void(HttpResponse<SSL> *, HttpRequest *)> handler) {
|
TemplatedApp &&del(std::string pattern, fu2::unique_function<void(HttpResponse<SSL> *, HttpRequest *)> &&handler) {
|
||||||
httpContext->onHttp("delete", pattern, handler);
|
httpContext->onHttp("delete", pattern, std::move(handler));
|
||||||
return std::move(*this);
|
return std::move(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplatedApp &&patch(std::string pattern, std::function<void(HttpResponse<SSL> *, HttpRequest *)> handler) {
|
TemplatedApp &&patch(std::string pattern, fu2::unique_function<void(HttpResponse<SSL> *, HttpRequest *)> &&handler) {
|
||||||
httpContext->onHttp("patch", pattern, handler);
|
httpContext->onHttp("patch", pattern, std::move(handler));
|
||||||
return std::move(*this);
|
return std::move(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplatedApp &&put(std::string pattern, std::function<void(HttpResponse<SSL> *, HttpRequest *)> handler) {
|
TemplatedApp &&put(std::string pattern, fu2::unique_function<void(HttpResponse<SSL> *, HttpRequest *)> &&handler) {
|
||||||
httpContext->onHttp("put", pattern, handler);
|
httpContext->onHttp("put", pattern, std::move(handler));
|
||||||
return std::move(*this);
|
return std::move(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplatedApp &&head(std::string pattern, std::function<void(HttpResponse<SSL> *, HttpRequest *)> handler) {
|
TemplatedApp &&head(std::string pattern, fu2::unique_function<void(HttpResponse<SSL> *, HttpRequest *)> &&handler) {
|
||||||
httpContext->onHttp("head", pattern, handler);
|
httpContext->onHttp("head", pattern, std::move(handler));
|
||||||
return std::move(*this);
|
return std::move(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplatedApp &&connect(std::string pattern, std::function<void(HttpResponse<SSL> *, HttpRequest *)> handler) {
|
TemplatedApp &&connect(std::string pattern, fu2::unique_function<void(HttpResponse<SSL> *, HttpRequest *)> &&handler) {
|
||||||
httpContext->onHttp("connect", pattern, handler);
|
httpContext->onHttp("connect", pattern, std::move(handler));
|
||||||
return std::move(*this);
|
return std::move(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplatedApp &&trace(std::string pattern, std::function<void(HttpResponse<SSL> *, HttpRequest *)> handler) {
|
TemplatedApp &&trace(std::string pattern, fu2::unique_function<void(HttpResponse<SSL> *, HttpRequest *)> &&handler) {
|
||||||
httpContext->onHttp("trace", pattern, handler);
|
httpContext->onHttp("trace", pattern, std::move(handler));
|
||||||
return std::move(*this);
|
return std::move(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This one catches any method */
|
/* This one catches any method */
|
||||||
TemplatedApp &&any(std::string pattern, std::function<void(HttpResponse<SSL> *, HttpRequest *)> handler) {
|
TemplatedApp &&any(std::string pattern, fu2::unique_function<void(HttpResponse<SSL> *, HttpRequest *)> &&handler) {
|
||||||
httpContext->onHttp("*", pattern, handler);
|
httpContext->onHttp("*", pattern, std::move(handler));
|
||||||
return std::move(*this);
|
return std::move(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplatedApp &&listen(int port, std::function<void(us_listen_socket *)> handler) {
|
TemplatedApp &&listen(int port, fu2::unique_function<void(us_listen_socket *)> &&handler) {
|
||||||
handler(httpContext->listen(nullptr, port, 0));
|
handler(httpContext->listen(nullptr, port, 0));
|
||||||
return std::move(*this);
|
return std::move(*this);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -30,6 +30,8 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
#include "f2/function2.hpp"
|
||||||
|
|
||||||
namespace uWS {
|
namespace uWS {
|
||||||
template<bool> struct HttpResponse;
|
template<bool> struct HttpResponse;
|
||||||
|
|
||||||
@@ -306,10 +308,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Register an HTTP route handler acording to URL pattern */
|
/* Register an HTTP route handler acording to URL pattern */
|
||||||
void onHttp(std::string method, std::string pattern, std::function<void(uWS::HttpResponse<SSL> *, uWS::HttpRequest *)> handler) {
|
void onHttp(std::string method, std::string pattern, fu2::unique_function<void(HttpResponse<SSL> *, HttpRequest *)> &&handler) {
|
||||||
HttpContextData<SSL> *httpContextData = getSocketContextData();
|
HttpContextData<SSL> *httpContextData = getSocketContextData();
|
||||||
|
|
||||||
httpContextData->router.add(method, pattern, [handler](typename HttpContextData<SSL>::RouterData &user, std::pair<int, std::string_view *> params) {
|
httpContextData->router.add(method, pattern, [handler = std::move(handler)](typename HttpContextData<SSL>::RouterData &user, std::pair<int, std::string_view *> params) mutable {
|
||||||
user.httpRequest->setYield(false);
|
user.httpRequest->setYield(false);
|
||||||
user.httpRequest->setParameters(params);
|
user.httpRequest->setParameters(params);
|
||||||
handler(user.httpResponse, user.httpRequest);
|
handler(user.httpResponse, user.httpRequest);
|
||||||
|
|||||||
Reference in New Issue
Block a user