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 += " \"transactionId\": \"OSRM Routing Engine JSON Descriptor (beta)\"\n";
|
||||
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:
|
||||
};
|
||||
|
@ -247,16 +247,6 @@ public:
|
||||
"\t</Placemark>\n";
|
||||
}
|
||||
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:
|
||||
};
|
||||
|
@ -120,7 +120,13 @@ public:
|
||||
unsigned int distance = sEngine->ComputeRoute(phantomNodes, path, startCoord, targetCoord);
|
||||
reply.status = http::Reply::ok;
|
||||
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:
|
||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||
break;
|
||||
@ -131,10 +137,48 @@ public:
|
||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||
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 path;
|
||||
delete phantomNodes;
|
||||
|
@ -69,14 +69,18 @@ public:
|
||||
std::string p = item.substr(0, found);
|
||||
std::transform(p.begin(), p.end(), p.begin(), (int(*)(int)) std::tolower);
|
||||
std::string o = item.substr(found+1);
|
||||
if("jsonp" != p)
|
||||
std::transform(o.begin(), o.end(), o.begin(), (int(*)(int)) std::tolower);
|
||||
routeParameters.options.Set(p, o);
|
||||
}
|
||||
}
|
||||
|
||||
// std::cout << "[debug] found handler for '" << command << "' at version: " << pluginMap.Find(command)->GetVersionString() << std::endl;
|
||||
// std::cout << "[debug] remaining parameters: " << parameters.size() << std::endl;
|
||||
rep.status = Reply::ok;
|
||||
_pluginVector[pluginMap.Find(command)]->HandleRequest(routeParameters, rep );
|
||||
|
||||
// std::cout << rep.content << std::endl;
|
||||
} else {
|
||||
rep = Reply::stockReply(Reply::badRequest);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user