diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-04-12 20:05:05 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-04-12 20:05:05 +0800 |
| commit | 54adacb8316bd23f27265751e9ac8ef35b9ec892 (patch) | |
| tree | c2abc07975598dc25ac2642825fc95b65edb980b /ricochet/src/net | |
| parent | 79ab6fcb6e74109c46e836594b2cc1ead87d7b30 (diff) | |
| download | rcc-project-54adacb8316bd23f27265751e9ac8ef35b9ec892.tar.gz rcc-project-54adacb8316bd23f27265751e9ac8ef35b9ec892.tar.xz | |
feat: add page title extraction, URL normalization, DuckDuckGo tracker stripping, and text wrapping support
Diffstat (limited to 'ricochet/src/net')
| -rw-r--r-- | ricochet/src/net/http_client.cc | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/ricochet/src/net/http_client.cc b/ricochet/src/net/http_client.cc index 5cf6a30..143e067 100644 --- a/ricochet/src/net/http_client.cc +++ b/ricochet/src/net/http_client.cc @@ -39,7 +39,6 @@ struct ParsedUrl std::expected<ParsedUrl, std::string> parse_url( std::string_view url ) { std::string_view prefix = "http://"; - if ( url.starts_with( "https://" ) ) { prefix = "https://"; } else if ( url.starts_with( "http://" ) ) { @@ -49,17 +48,20 @@ std::expected<ParsedUrl, std::string> parse_url( std::string_view url ) } url.remove_prefix( prefix.length() ); - auto slash_pos = url.find( '/' ); + + const auto sep_pos = url.find_first_of( "/?#" ); ParsedUrl result; - if ( slash_pos == std::string_view::npos ) { + if ( sep_pos == std::string_view::npos ) { result.host = std::string( url ); result.path = "/"; } else { - result.host = std::string( url.substr( 0, slash_pos ) ); - result.path = std::string( url.substr( slash_pos ) ); + result.host = std::string( url.substr( 0, sep_pos ) ); + result.path = std::string( url.substr( sep_pos ) ); + if ( result.path[0] != '/' ) { + result.path.insert( 0, "/" ); + } } - return result; } |
