aboutsummaryrefslogtreecommitdiff
path: root/src/net/http_client.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-04-12 20:05:05 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-04-12 20:05:05 +0800
commit5a8bb74e922f9ecebffbb03832b559f9dec21473 (patch)
treee2dc0e2f8a9d1c0dc27fc79a823893ae650bdb51 /src/net/http_client.cc
parent3e204040c9a9fec810112933d0d81cecbd268943 (diff)
downloadrwebbrowser-5a8bb74e922f9ecebffbb03832b559f9dec21473.tar.gz
rwebbrowser-5a8bb74e922f9ecebffbb03832b559f9dec21473.tar.xz
feat: add page title extraction, URL normalization, DuckDuckGo tracker stripping, and text wrapping support
Diffstat (limited to 'src/net/http_client.cc')
-rw-r--r--src/net/http_client.cc14
1 files changed, 8 insertions, 6 deletions
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<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;
}