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

Method HandleRequest

src/server/request_handler.cpp:85–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85void RequestHandler::HandleRequest(const Request &current_request,
86 Response &current_reply,
87 const boost::asio::ip::address &remote_address)
88{
89 // Defensive reset: Connection also resets before calling us.
90 current_reply = {};
91
92 if (!service_handler)
93 {
94 SetInternalServerError(current_reply);
95 util::Log(logWARNING) << "No service handler registered." << std::endl;
96 return;
97 }
98
99 const auto tid = std::this_thread::get_id();
100
101 // parse command
102 try
103 {
104 TIMER_START(request_duration);
105 std::string request_string;
106 util::URIDecode(std::string(current_request.target()), request_string);
107
108 util::Log(logDEBUG) << "[req][" << tid << "] " << request_string;
109
110 auto api_iterator = request_string.begin();
111 auto maybe_parsed_url = api::parseURL(api_iterator, request_string.end());
112 ServiceHandler::ResultT result;
113 bhttp::status response_status = bhttp::status::ok;
114
115 // check if there was an error with the request
116 if (maybe_parsed_url && api_iterator == request_string.end())
117 {
118
119 const engine::Status status =
120 service_handler->RunQuery(*std::move(maybe_parsed_url), result);
121 if (status != engine::Status::Ok)
122 {
123 // 4xx bad request return code
124 response_status = bhttp::status::bad_request;
125 }
126 else
127 {
128 BOOST_ASSERT(status == engine::Status::Ok);
129 }
130 }
131 else
132 {
133 const auto position = std::distance(request_string.begin(), api_iterator);
134 BOOST_ASSERT(position >= 0);
135 const auto context_begin =
136 request_string.begin() + ((position < 3) ? 0 : (position - 3UL));
137 BOOST_ASSERT(context_begin >= request_string.begin());
138 const auto context_end = request_string.begin() +
139 std::min<std::size_t>(position + 3UL, request_string.size());
140 BOOST_ASSERT(context_end <= request_string.end());
141 std::string context(context_begin, context_end);
142

Callers 1

process_requestMethod · 0.45

Calls 15

SetInternalServerErrorFunction · 0.85
LogClass · 0.85
URIDecodeFunction · 0.85
to_stringFunction · 0.85
SendResponseFunction · 0.85
timeFunction · 0.85
HeaderOrEmptyFunction · 0.85
whatMethod · 0.80
parseURLFunction · 0.50
ObjectClass · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected