Strip the scheme prefix off a Langfuse host URL and return the leading sub-path (everything after the host[:port], e.g. "/langfuse" if hosted under a sub-path). httplib::Client's URL constructor handles host/port/TLS itself, so we only need to extract the optional base path.
| 30 | // a sub-path). httplib::Client's URL constructor handles host/port/TLS itself, |
| 31 | // so we only need to extract the optional base path. |
| 32 | std::string extract_base_path(const std::string& url) { |
| 33 | std::string s = url; |
| 34 | if (s.starts_with("https://")) |
| 35 | s = s.substr(8); |
| 36 | else if (s.starts_with("http://")) |
| 37 | s = s.substr(7); |
| 38 | auto slash = s.find('/'); |
| 39 | if (slash == std::string::npos) |
| 40 | return {}; |
| 41 | std::string p = s.substr(slash); |
| 42 | if (!p.empty() && p.back() == '/') |
| 43 | p.pop_back(); |
| 44 | return p; |
| 45 | } |
| 46 | |
| 47 | // Strip any trailing slash from a scheme+host[:port] URL so httplib's URL ctor |
| 48 | // gets exactly what it expects. |