Marek Kotewicz
10 years ago
4 changed files with 50 additions and 3 deletions
@ -0,0 +1,29 @@ |
|||||
|
|
||||
|
#include "CorsHttpServer.h" |
||||
|
|
||||
|
namespace jsonrpc |
||||
|
{ |
||||
|
|
||||
|
bool CorsHttpServer::SendResponse(const std::string &response, void *addInfo) |
||||
|
{ |
||||
|
struct mg_connection* conn = (struct mg_connection*) addInfo; |
||||
|
if (mg_printf(conn, "HTTP/1.1 200 OK\r\n" |
||||
|
"Content-Type: application/json\r\n" |
||||
|
"Content-Length: %d\r\n" |
||||
|
"Access-Control-Allow-Origin: *\r\n" |
||||
|
"Access-Control-Allow-Headers: Content-Type\r\n" |
||||
|
"\r\n" |
||||
|
"%s",(int)response.length(), response.c_str()) > 0) |
||||
|
|
||||
|
|
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
|
||||
|
#include <jsonrpc/connectors/httpserver.h> |
||||
|
|
||||
|
namespace jsonrpc |
||||
|
{ |
||||
|
|
||||
|
class CorsHttpServer : public HttpServer |
||||
|
{ |
||||
|
public: |
||||
|
using HttpServer::HttpServer; |
||||
|
bool virtual SendResponse(const std::string& response, |
||||
|
void* addInfo = NULL); |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
|
Loading…
Reference in new issue