Newer
Older
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
//
// Created by armin on 16.11.17.
//
#include "GooglePushHandler.h"
#include "../models/GooglePushModel.h"
void GooglePushHandler::onRequest(std::unique_ptr<HTTPMessage> headers) noexcept {
}
void GooglePushHandler::onBody(std::unique_ptr<folly::IOBuf> body) noexcept {
if(mBody){
mBody->prependChain(std::move(body));
} else{
mBody = std::move(body);
}
}
void GooglePushHandler::onUpgrade(proxygen::UpgradeProtocol prot) noexcept {
}
void GooglePushHandler::onEOM() noexcept {
if (mBody) {
try {
std::string body(reinterpret_cast<const char *>(mBody->data()));
GooglePushModel googlePushModel(body);
std::string response;
if (googlePushModel.sendMessage()) {
ResponseBuilder(downstream_).status(200, "OK").body("").sendWithEOM();
} else {
ResponseBuilder(downstream_).status(500, "FAILURE").body("failed to send push mesage").sendWithEOM();
}
} catch (Exception &e) {
std::cout << "exception " << e.what() << std::endl;
ResponseBuilder(downstream_).status(500, "FAILURE").body("failed to send push mesage").sendWithEOM();
}
} else {
ResponseBuilder(downstream_).status(400, "BAD REQUEST").body("failed to send push message").sendWithEOM();
}
}
void GooglePushHandler::requestComplete() noexcept {
}
void GooglePushHandler::onError(ProxygenError err) noexcept {
}