33 response.
Header[
"Content-Type"] =
"application/json; charset=UTF-8";
34 response.
Header[
"Access-Control-Allow-Origin"] =
"*";
35 response.
Header[
"Access-Control-Allow-Methods"] =
"OPTIONS, GET, POST";
36 response.
Header[
"Access-Control-Allow-Headers"] =
"Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token";
38 if( request.
Method ==
"OPTIONS" ){
42 if( request.
Method ==
"GET" ){
46 if( depth < 1 ) depth = 1;
52 SGPropertyNode_ptr node = getRequestedNode(request );
64 if( request.
Method ==
"POST" ) {
65 SGPropertyNode_ptr node = getRequestedNode(request );
72 SG_LOG(SG_NETWORK,SG_INFO,
"JsonUriHandler: setting property from'" << request.
Content <<
"'" );
73 cJSON * json = cJSON_Parse( request.
Content.c_str() );
83 SG_LOG(SG_NETWORK,SG_INFO,
"JsonUriHandler: invalid request method '" << request.
Method <<
"'" );
84 response.
Header[
"Allow"] =
"OPTIONS, GET, POST";
91SGPropertyNode_ptr JsonUriHandler::getRequestedNode(
const HTTPRequest & request)
93 SG_LOG(SG_NETWORK,SG_INFO,
"JsonUriHandler: request is '" << request.
Uri <<
"'" );
94 string propertyPath = request.
Uri;
95 propertyPath = propertyPath.substr(
getUri().size() );
98 while( !propertyPath.empty() && propertyPath[ propertyPath.length()-1 ] ==
'/' )
99 propertyPath = propertyPath.substr(0,propertyPath.length()-1);
101 SGPropertyNode_ptr reply =
fgGetNode(
string(
"/") + propertyPath );
102 if( !reply.valid() ) {
103 SG_LOG(SG_NETWORK,SG_WARN,
"JsonUriHandler: requested node not found: '" << propertyPath <<
"'");
std::string get(const std::string &key) const
StringMap RequestVariables
static std::string toJsonString(bool indent, SGPropertyNode_ptr n, int depth, double timestamp=-1.0)
static void toProp(cJSON *json, SGPropertyNode_ptr base)
virtual bool handleRequest(const HTTPRequest &request, HTTPResponse &response, Connection *connection)
This method gets called from the httpd if a request has been detected on the connection.
const std::string & getUri() const
Getter for the URI this handler serves.
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
static int atoi(const string &str)
double fgGetDouble(const char *name, double defaultValue)
Get a double value for a property.
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.