Fabcoin Core  0.16.2
P2P Digital Currency
SafeHttpServer.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
23 #include <microhttpd.h>
24 #include <sstream>
25 #include "SafeHttpServer.h"
26 using namespace std;
27 using namespace dev;
28 
31 {
32  struct MHD_PostProcessor *postprocessor;
33  MHD_Connection* connection;
34  stringstream request;
35  jsonrpc::HttpServer* server;
36  int code;
37 };
38 
39 bool SafeHttpServer::SendResponse(string const& _response, void* _addInfo)
40 {
41  struct mhd_coninfo* client_connection = static_cast<struct mhd_coninfo*>(_addInfo);
42  struct MHD_Response *result = MHD_create_response_from_buffer(
43  _response.size(),
44  static_cast<void *>(const_cast<char *>(_response.c_str())),
45  MHD_RESPMEM_MUST_COPY
46  );
47 
48  MHD_add_response_header(result, "Content-Type", "application/json");
49  MHD_add_response_header(result, "Access-Control-Allow-Origin", m_allowedOrigin.c_str());
50 
51  int ret = MHD_queue_response(client_connection->connection, client_connection->code, result);
52  MHD_destroy_response(result);
53  return ret == MHD_YES;
54 }
55 
56 bool SafeHttpServer::SendOptionsResponse(void* _addInfo)
57 {
58  struct mhd_coninfo* client_connection = static_cast<struct mhd_coninfo*>(_addInfo);
59  struct MHD_Response *result = MHD_create_response_from_buffer(0, nullptr, MHD_RESPMEM_MUST_COPY);
60 
61  MHD_add_response_header(result, "Allow", "POST, OPTIONS");
62  MHD_add_response_header(result, "Access-Control-Allow-Origin", m_allowedOrigin.c_str());
63  MHD_add_response_header(result, "Access-Control-Allow-Headers", "origin, content-type, accept");
64  MHD_add_response_header(result, "DAV", "1");
65 
66  int ret = MHD_queue_response(client_connection->connection, client_connection->code, result);
67  MHD_destroy_response(result);
68  return ret == MHD_YES;
69 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
struct MHD_PostProcessor * postprocessor
std::hash for asio::adress
Definition: Common.h:323
stringstream request
structure copied from libjson-rpc-cpp httpserver version 0.6.0
MHD_Connection * connection
jsonrpc::HttpServer * server