Skip to content

Truly independent web browser

LibURL: Let Rust code parse a host and lend one to C++

Shannon Boothd307447bfd74
diff --git a/Libraries/LibURL/Rust/src/ffi/url.rs b/Libraries/LibURL/Rust/src/ffi/url.rs
index 4943f6b05e4..f4ae26b548e 100644
--- a/Libraries/LibURL/Rust/src/ffi/url.rs
+++ b/Libraries/LibURL/Rust/src/ffi/url.rs
@@ -120,7 +120,7 @@ pub struct FfiUrlHost {
}
impl FfiUrlHost {
- pub(crate) fn new(kind: HostKind, serialized_host: &str) -> Self {
+ pub fn new(kind: HostKind, serialized_host: &str) -> Self {
let mut host = Self {
kind,
ipv4: [0; 4],
diff --git a/Libraries/LibURL/Rust/src/lib.rs b/Libraries/LibURL/Rust/src/lib.rs
index cc308d20caf..5a1bb1da217 100644
--- a/Libraries/LibURL/Rust/src/lib.rs
+++ b/Libraries/LibURL/Rust/src/lib.rs
@@ -20,6 +20,7 @@ mod textcodec;
pub mod url;
pub use ffi::origin::FfiOrigin;
+pub use ffi::url::FfiUrlHost;
pub use ffi::url::RustUrl;
pub use url::BasicParseOptions;
pub use url::State;
diff --git a/Libraries/LibURL/Rust/src/url/mod.rs b/Libraries/LibURL/Rust/src/url/mod.rs
index 424de5d371e..3d7fe98de8f 100644
--- a/Libraries/LibURL/Rust/src/url/mod.rs
+++ b/Libraries/LibURL/Rust/src/url/mod.rs
@@ -14,6 +14,8 @@ mod scheme;
mod serialize;
mod types;
+use crate::origin::Host;
+
pub use self::blob_url_entry::BlobUrlEntry;
pub(crate) use self::host::parse_host_into;
pub use self::input::UrlInput;
@@ -57,6 +59,13 @@ pub fn basic_parse<'a>(input: impl Into<UrlInput<'a>>, options: BasicParseOption
parser::basic_parse(input.into(), options.base_url, options.encoding)
}
+// https://url.spec.whatwg.org/#concept-host-parser
+pub fn parse_host<'a>(input: impl Into<UrlInput<'a>>) -> Option<Host> {
+ let mut serialization = String::new();
+ let kind = parse_host_into(input.into(), false, &mut serialization)?;
+ Some(Host { kind, serialization })
+}
+
pub fn create_with_data(mime_type: &str, payload: &str, is_base64: bool) -> Url {
let mut builder = String::from(mime_type);
if is_base64 {