MCPcopy Create free account
hub / github.com/WallBreaker2/op / configure_endpoint

Function configure_endpoint

libop/network/HttpClient.cpp:238–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236// --- shared endpoint configuration ---
237
238int configure_endpoint(std::string &m_endpoint, int &m_timeout_ms, const std::wstring &engine,
239 const std::wstring &dllName, const std::vector<std::string> &argvs,
240 const std::function<bool(const std::string &, std::string &)> &try_alias,
241 const char *default_path_suffix, const char *label, const char *default_endpoint_env_url,
242 const char *default_endpoint_env_backend, int default_timeout_ms_fallback) {
243 std::string endpoint = m_endpoint;
244 int timeout_ms = m_timeout_ms;
245
246 if (endpoint.empty()) {
247 // resolve default from env or alias
248 if (default_endpoint_env_url) {
249 std::string url_env = getenv_trimmed(default_endpoint_env_url);
250 if (!url_env.empty()) {
251 endpoint = url_env;
252 }
253 }
254 if (endpoint.empty() && default_endpoint_env_backend) {
255 std::string backend_env = getenv_trimmed(default_endpoint_env_backend);
256 if (!backend_env.empty()) {
257 std::string tmp;
258 if (try_alias(backend_env, tmp))
259 endpoint = tmp;
260 }
261 }
262 }
263 if (timeout_ms <= 0 && default_timeout_ms_fallback > 0) {
264 // try resolve timeout from env (OCR uses OP_OCR_TIMEOUT_MS, YOLO uses OP_YOLO_TIMEOUT_MS)
265 // the caller passes the default via the function — we just keep existing timeout_ms logic
266 }
267
268 auto maybe_set_endpoint = [&](const std::string &candidate) {
269 std::string resolved;
270 if (resolve_endpoint_candidate(candidate, resolved, try_alias)) {
271 endpoint = resolved;
272 }
273 };
274
275 if (!engine.empty()) {
276 maybe_set_endpoint(_ws2string(engine));
277 }
278 if (!dllName.empty()) {
279 maybe_set_endpoint(_ws2string(dllName));
280 }
281
282 for (const auto &arg : argvs) {
283 if (arg.rfind("--url=", 0) == 0) {
284 maybe_set_endpoint(arg.substr(6));
285 continue;
286 }
287 if (arg.rfind("--timeout=", 0) == 0) {
288 const int v = atoi(arg.substr(10).c_str());
289 if (v > 0) {
290 timeout_ms = v;
291 }
292 continue;
293 }
294 if (starts_with_http(arg)) {
295 endpoint = arg;

Callers 2

initMethod · 0.85
initMethod · 0.85

Calls 6

getenv_trimmedFunction · 0.85
_ws2stringFunction · 0.85
starts_with_httpFunction · 0.85
normalize_endpointFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected