From 5a8bb74e922f9ecebffbb03832b559f9dec21473 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sun, 12 Apr 2026 20:05:05 +0800 Subject: feat: add page title extraction, URL normalization, DuckDuckGo tracker stripping, and text wrapping support --- src/net/http_client.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/net') diff --git a/src/net/http_client.cc b/src/net/http_client.cc index 5cf6a30..143e067 100644 --- a/src/net/http_client.cc +++ b/src/net/http_client.cc @@ -39,7 +39,6 @@ struct ParsedUrl std::expected 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 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; } -- cgit v1.2.3