jsonp support by adding "output=json&jsonp=parseResponse" to URL
This commit is contained in:
parent
51d0b94e90
commit
9514c4b811
@ -283,16 +283,6 @@ public:
|
|||||||
reply.content += " ],\n";
|
reply.content += " ],\n";
|
||||||
reply.content += " \"transactionId\": \"OSRM Routing Engine JSON Descriptor (beta)\"\n";
|
reply.content += " \"transactionId\": \"OSRM Routing Engine JSON Descriptor (beta)\"\n";
|
||||||
reply.content += "}";
|
reply.content += "}";
|
||||||
|
|
||||||
reply.headers.resize(3);
|
|
||||||
reply.headers[0].name = "Content-Length";
|
|
||||||
intToString(reply.content.size(), tmp);
|
|
||||||
reply.headers[0].value = tmp;
|
|
||||||
reply.headers[1].name = "Content-Type";
|
|
||||||
reply.headers[1].value = "application/vnd.google-earth.kml+xml; charset=UTF-8";
|
|
||||||
reply.headers[2].name = "Content-Disposition";
|
|
||||||
reply.headers[2].value = "attachment; filename=\"route.kml\"";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
@ -247,16 +247,6 @@ public:
|
|||||||
"\t</Placemark>\n";
|
"\t</Placemark>\n";
|
||||||
}
|
}
|
||||||
reply.content += "</Document>\n</kml>";
|
reply.content += "</Document>\n</kml>";
|
||||||
|
|
||||||
reply.headers.resize(3);
|
|
||||||
reply.headers[0].name = "Content-Length";
|
|
||||||
intToString(reply.content.size(), tmp);
|
|
||||||
reply.headers[0].value = tmp;
|
|
||||||
reply.headers[1].name = "Content-Type";
|
|
||||||
reply.headers[1].value = "application/vnd.google-earth.kml+xml; charset=UTF-8";
|
|
||||||
reply.headers[2].name = "Content-Disposition";
|
|
||||||
reply.headers[2].value = "attachment; filename=\"route.kml\"";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
@ -120,7 +120,13 @@ public:
|
|||||||
unsigned int distance = sEngine->ComputeRoute(phantomNodes, path, startCoord, targetCoord);
|
unsigned int distance = sEngine->ComputeRoute(phantomNodes, path, startCoord, targetCoord);
|
||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
BaseDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > * desc;
|
BaseDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > * desc;
|
||||||
switch(descriptorTable[routeParameters.options.Find("output")]){
|
std::string JSONParameter = routeParameters.options.Find("jsonp");
|
||||||
|
if("" != JSONParameter) {
|
||||||
|
reply.content += JSONParameter;
|
||||||
|
reply.content += "(\n";
|
||||||
|
}
|
||||||
|
unsigned descriptorType = descriptorTable[routeParameters.options.Find("output")];
|
||||||
|
switch(descriptorType){
|
||||||
case 0:
|
case 0:
|
||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||||
break;
|
break;
|
||||||
@ -131,10 +137,48 @@ public:
|
|||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > desc;
|
|
||||||
desc->Run(reply, path, phantomNodes, sEngine, distance);
|
|
||||||
|
|
||||||
std::cout << reply.content << std::endl;
|
desc->Run(reply, path, phantomNodes, sEngine, distance);
|
||||||
|
if("" != JSONParameter) {
|
||||||
|
reply.content += ")\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
reply.headers.resize(3);
|
||||||
|
reply.headers[0].name = "Content-Length";
|
||||||
|
std::string tmp;
|
||||||
|
intToString(reply.content.size(), tmp);
|
||||||
|
reply.headers[0].value = tmp;
|
||||||
|
switch(descriptorType){
|
||||||
|
case 0:
|
||||||
|
reply.headers[1].name = "Content-Type";
|
||||||
|
reply.headers[1].value = "application/vnd.google-earth.kml+xml; charset=UTF-8";
|
||||||
|
reply.headers[2].name = "Content-Disposition";
|
||||||
|
reply.headers[2].value = "attachment; filename=\"route.kml\"";
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if("" != JSONParameter){
|
||||||
|
reply.headers[1].name = "Content-Type";
|
||||||
|
reply.headers[1].value = "text/javascript";
|
||||||
|
reply.headers[2].name = "Content-Disposition";
|
||||||
|
reply.headers[2].value = "attachment; filename=\"route.js\"";
|
||||||
|
} else {
|
||||||
|
reply.headers[1].name = "Content-Type";
|
||||||
|
reply.headers[1].value = "application/json";
|
||||||
|
reply.headers[2].name = "Content-Disposition";
|
||||||
|
reply.headers[2].value = "attachment; filename=\"route.json\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
reply.headers[1].name = "Content-Type";
|
||||||
|
reply.headers[1].value = "application/vnd.google-earth.kml+xml; charset=UTF-8";
|
||||||
|
reply.headers[2].name = "Content-Disposition";
|
||||||
|
reply.headers[2].value = "attachment; filename=\"route.kml\"";
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
delete desc;
|
delete desc;
|
||||||
delete path;
|
delete path;
|
||||||
delete phantomNodes;
|
delete phantomNodes;
|
||||||
|
@ -69,14 +69,18 @@ public:
|
|||||||
std::string p = item.substr(0, found);
|
std::string p = item.substr(0, found);
|
||||||
std::transform(p.begin(), p.end(), p.begin(), (int(*)(int)) std::tolower);
|
std::transform(p.begin(), p.end(), p.begin(), (int(*)(int)) std::tolower);
|
||||||
std::string o = item.substr(found+1);
|
std::string o = item.substr(found+1);
|
||||||
std::transform(o.begin(), o.end(), o.begin(), (int(*)(int)) std::tolower);
|
if("jsonp" != p)
|
||||||
|
std::transform(o.begin(), o.end(), o.begin(), (int(*)(int)) std::tolower);
|
||||||
routeParameters.options.Set(p, o);
|
routeParameters.options.Set(p, o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::cout << "[debug] found handler for '" << command << "' at version: " << pluginMap.Find(command)->GetVersionString() << std::endl;
|
// std::cout << "[debug] found handler for '" << command << "' at version: " << pluginMap.Find(command)->GetVersionString() << std::endl;
|
||||||
// std::cout << "[debug] remaining parameters: " << parameters.size() << std::endl;
|
// std::cout << "[debug] remaining parameters: " << parameters.size() << std::endl;
|
||||||
rep.status = Reply::ok;
|
rep.status = Reply::ok;
|
||||||
_pluginVector[pluginMap.Find(command)]->HandleRequest(routeParameters, rep );
|
_pluginVector[pluginMap.Find(command)]->HandleRequest(routeParameters, rep );
|
||||||
|
|
||||||
|
// std::cout << rep.content << std::endl;
|
||||||
} else {
|
} else {
|
||||||
rep = Reply::stockReply(Reply::badRequest);
|
rep = Reply::stockReply(Reply::badRequest);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user