-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUsuarioHandler.cpp
67 lines (56 loc) · 1.84 KB
/
UsuarioHandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Created by victor on 15/10/17.
//
//
#include "UsuarioHandler.h"
#include <proxygen/httpserver/ResponseBuilder.h>
#include "AuthenticationProcessor.h"
#include "AddUserProcessor.h"
using std::string;
using namespace proxygen;
namespace cxxdoor {
void UsuarioHandler::onRequest(std::unique_ptr<HTTPMessage> headers) noexcept {
const string path = headers->getPath();
DLOG(INFO) << "handling onRequest: " << path;
if (path == "/user/authenticate" && headers->getMethodString() == "POST") {
_commandProcessor = std::make_shared<AuthenticationProcessor>(this->downstream_);
} else if (path == "/user" && headers->getMethodString() == "POST") {
_commandProcessor = std::make_shared<AddUserProcessor>(this->downstream_);
} else {
ResponseBuilder(downstream_).status(500, "Could not handle request")
.sendWithEOM();
}
}
void UsuarioHandler::onBody(std::unique_ptr<folly::IOBuf> body) noexcept {
DLOG(INFO) << "handling onBody";
if (_commandProcessor)
_commandProcessor->onBody(std::move(body));
}
void UsuarioHandler::onUpgrade(UpgradeProtocol prot) noexcept {
DLOG(INFO) << "handling onUpgrade";
}
void UsuarioHandler::onEOM() noexcept {
DLOG(INFO) << "handling onEOM";
if (_commandProcessor)
_commandProcessor->onEOM();
}
void UsuarioHandler::requestComplete() noexcept {
DLOG(INFO) << "handling requestComplete";
delete this;
}
void UsuarioHandler::onError(ProxygenError err) noexcept {
DLOG(INFO) << "handling onError";
delete this;
}
UsuarioHandler::~UsuarioHandler() {
}
void UsuarioHandler::setResponseHandler(ResponseHandler *handler) noexcept {
RequestHandler::setResponseHandler(handler);
}
void UsuarioHandler::onEgressPaused() noexcept {
RequestHandler::onEgressPaused();
}
void UsuarioHandler::onEgressResumed() noexcept {
RequestHandler::onEgressResumed();
}
UsuarioHandler::UsuarioHandler() {}
}