srctree

Robin Linden parent 5563f53b d0c25c4b
browser/engine: Support origin-relative uris

inlinesplit
browser/engine.cpp added: 23, removed: 2, total 21
@@ -39,6 +39,12 @@ protocol::Error Engine::navigate(uri::Uri uri) {
uri.path = "/";
}
 
if (uri.scheme.empty() && uri.authority.host.empty() && uri.path.starts_with('/')) {
spdlog::info("Handling origin-relative URL {}", uri.uri);
uri = uri::Uri::parse(fmt::format("{}://{}{}", uri_.scheme, uri_.authority.host, uri.uri)).value();
spdlog::info("Transformed origin-relative URL to {}", uri.uri);
}
 
uri_ = uri;
response_ = protocol_handler_->handle(uri_);
while (response_.err == protocol::Error::Ok && is_redirect(response_.status_line.status_code)) {
 
browser/engine_test.cpp added: 23, removed: 2, total 21
@@ -13,6 +13,7 @@
 
using namespace std::literals;
using etest::expect;
using etest::expect_eq;
using etest::require;
 
namespace {
@@ -75,5 +76,19 @@ int main() {
expect(success);
});
 
etest::test("origin-relative uri", [] {
browser::Engine e{std::make_unique<FakeProtocolHandler>(protocol::Response{.err = protocol::Error::Ok})};
 
// TOOD(robinlinden)
// `/` being included as the path here is important as the uri-parser
// currently doesn't do normalization, and the browser engine patches
// the uri to work when the path is empty.
e.navigate(*uri::Uri::parse("hax://example.com/"));
expect_eq(e.uri(), *uri::Uri::parse("hax://example.com/"));
 
e.navigate(*uri::Uri::parse("/test"));
expect_eq(e.uri(), *uri::Uri::parse("hax://example.com/test"));
});
 
return etest::run_all_tests();
}