33 #ifndef _IDENTT_HRPC_PROTO_SERVICE_BASE_HPP_ 34 #define _IDENTT_HRPC_PROTO_SERVICE_BASE_HPP_ 37 #include "../proto/Hrpc.pb.h" 42 template <
class HttpServerT>
57 auto it=request->header.find(
"Content-Type");
58 if(it==request->header.end())it=request->header.find(
"Accept");
59 if(it==request->header.end())
return false;
60 if ( it->second.compare(0,17,
"application/proto",17)!=0)
return false;
61 it=request->header.find(
"Proto-Transfer-Encoding");
62 return ( it->second.compare(0,6,
"base64",6)==0);
77 bool SharedSecretOK(
typename HttpServerT::ReqPtr request, std::string sharedkey)
79 auto it=request->header.find(
"Shared-Secret");
80 if(it==request->header.end())
return false;
81 return ( it->second == sharedkey );
95 auto it=request->header.find(
"Service-Name");
96 return (it==request->header.end()) ? 0 : std::stoi(it->second);
115 typename HttpServerT::RespPtr response,
116 typename HttpServerT::ReqPtr request,
117 std::string& payload)
119 *response <<
"HTTP/" << request->http_version <<
" 200 OK\r\n";
120 *response <<
"Service-Name: " <<
ServiceName(request) <<
"\r\n";
121 *response <<
"Content-Type: " <<
"application/proto" <<
"\r\n";
122 *response <<
"Proto-Transfer-Encoding: " <<
"base64" <<
"\r\n";
123 *response <<
"Content-Length: " << payload.length() <<
"\r\n";
124 *response <<
"\r\n" << payload.c_str();
143 typename HttpServerT::RespPtr response,
144 typename HttpServerT::ReqPtr request,
145 std::string&& payload)
147 *response <<
"HTTP/" << request->http_version <<
" 200 OK\r\n";
148 *response <<
"Service-Name: " <<
ServiceName(request) <<
"\r\n";
149 *response <<
"Content-Type: " <<
"application/proto" <<
"\r\n";
150 *response <<
"Proto-Transfer-Encoding: " <<
"base64" <<
"\r\n";
151 *response <<
"Content-Length: " << payload.length() <<
"\r\n";
152 *response <<
"\r\n" << payload.c_str();
174 typename HttpServerT::RespPtr response,
175 typename HttpServerT::ReqPtr request,
176 int ecode, std::string& emsg)
178 *response <<
"HTTP/" << request->http_version <<
" 200 OK\r\n";
179 *response <<
"Service-Name: " <<
ServiceName(request) <<
"\r\n";
180 *response <<
"Service-Error: " << ecode <<
"\r\n";
181 *response <<
"Content-Type: application/proto" <<
"\r\n";
182 *response <<
"Content-Length: " << emsg.length() <<
"\r\n";
183 *response <<
"\r\n" << emsg.c_str();
void ServiceOKAction(typename HttpServerT::RespPtr response, typename HttpServerT::ReqPtr request, std::string &payload)
ServiceOKAction : OK Action template for service.
Definition: ProtoServiceBase.hpp:114
int ServiceName(typename HttpServerT::ReqPtr request)
ServiceName : Check protobuf request service name.
Definition: ProtoServiceBase.hpp:93
void ServiceOKAction(typename HttpServerT::RespPtr response, typename HttpServerT::ReqPtr request, std::string &&payload)
ServiceOKAction : OK Action template for service.
Definition: ProtoServiceBase.hpp:142
Definition: CryptoBase.hpp:49
bool SharedSecretOK(typename HttpServerT::ReqPtr request, std::string sharedkey)
SharedSecretOK : Check if shared key header is present and ok.
Definition: ProtoServiceBase.hpp:77
void ServiceErrAction(typename HttpServerT::RespPtr response, typename HttpServerT::ReqPtr request, int ecode, std::string &emsg)
ServiceErrAction : Error Action template for service.
Definition: ProtoServiceBase.hpp:173
Definition: ProtoServiceBase.hpp:43
bool ProtoRequest(typename HttpServerT::ReqPtr request)
ProtoRequest : Check if request is protobuf from Content-Type and Accept fields.
Definition: ProtoServiceBase.hpp:55