MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / SendResponse

Function SendResponse

src/server/request_handler.cpp:39–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39void SendResponse(ServiceHandler::ResultT &result,
40 Response &current_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
79void RequestHandler::RegisterServiceHandler(

Callers 1

HandleRequestMethod · 0.85

Calls 9

copyFunction · 0.85
setMethod · 0.80
GetSizeMethod · 0.80
renderFunction · 0.50
resizeMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
cbeginMethod · 0.45
cendMethod · 0.45

Tested by

no test coverage detected