| 37 | } |
| 38 | |
| 39 | void SendResponse(ServiceHandler::ResultT &result, |
| 40 | Response ¤t_reply, |
| 41 | const bhttp::status status) |
| 42 | { |
| 43 | |
| 44 | current_reply.result(status); |
| 45 | current_reply.set("Access-Control-Allow-Origin", "*"); |
| 46 | current_reply.set("Access-Control-Allow-Methods", "GET"); |
| 47 | current_reply.set("Access-Control-Allow-Headers", "X-Requested-With, Content-Type"); |
| 48 | if (std::holds_alternative<util::json::Object>(result)) |
| 49 | { |
| 50 | current_reply.set(bhttp::field::content_type, "application/json; charset=UTF-8"); |
| 51 | current_reply.set(bhttp::field::content_disposition, "inline; filename=\"response.json\""); |
| 52 | |
| 53 | util::json::render(current_reply.body(), std::get<util::json::Object>(result)); |
| 54 | } |
| 55 | else if (std::holds_alternative<flatbuffers::FlatBufferBuilder>(result)) |
| 56 | { |
| 57 | auto &buffer = std::get<flatbuffers::FlatBufferBuilder>(result); |
| 58 | current_reply.body().resize(buffer.GetSize()); |
| 59 | std::copy(buffer.GetBufferPointer(), |
| 60 | buffer.GetBufferPointer() + buffer.GetSize(), |
| 61 | current_reply.body().begin()); |
| 62 | |
| 63 | current_reply.set(bhttp::field::content_type, |
| 64 | "application/x-flatbuffers;schema=osrm.engine.api.fbresult"); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | BOOST_ASSERT(std::holds_alternative<std::string>(result)); |
| 69 | current_reply.body().resize(std::get<std::string>(result).size()); |
| 70 | std::copy(std::get<std::string>(result).cbegin(), |
| 71 | std::get<std::string>(result).cend(), |
| 72 | current_reply.body().begin()); |
| 73 | |
| 74 | current_reply.set(bhttp::field::content_type, "application/x-protobuf"); |
| 75 | } |
| 76 | } |
| 77 | } // namespace |
| 78 | |
| 79 | void RequestHandler::RegisterServiceHandler( |