Kurlyk
Loading...
Searching...
No Matches
http_utils.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef KURLYK_HEADER_KURLYK_UTILS_HTTP_UTILS_HPP_INCLUDED
3#define KURLYK_HEADER_KURLYK_UTILS_HTTP_UTILS_HPP_INCLUDED
4
7
8namespace kurlyk {
9namespace utils {
10
14 inline std::string remove_http_prefix(const std::string& url) {
15 const std::string https_prefix = "https://";
16 const std::string http_prefix = "http://";
17
18 std::string modified_url = url;
19
20 // Find the position of "https://" or "http://"
21 std::size_t pos = modified_url.find(https_prefix);
22 if (pos == std::string::npos) {
23 pos = modified_url.find(http_prefix);
24 }
25
26 // If found, erase the substring
27 if (pos != std::string::npos) {
28 if (modified_url.compare(pos, https_prefix.length(), https_prefix) == 0) {
29 modified_url.erase(pos, https_prefix.length());
30 } else if (modified_url.compare(pos, http_prefix.length(), http_prefix) == 0) {
31 modified_url.erase(pos, http_prefix.length());
32 }
33 }
34
35 return modified_url;
36 }
37
38} // namespace utils
39} // namespace kurlyk
40
41#endif // KURLYK_HEADER_KURLYK_UTILS_HTTP_UTILS_HPP_INCLUDED
std::string remove_http_prefix(const std::string &url)
Removes the first occurrence of "https://" or "http://" from the given URL.
Primary namespace for the Kurlyk library, encompassing initialization, request management,...