diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-09-13 23:12:16 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-14 00:14:45 +0200 |
commit | d6cfa34667fe808975279c237d4ac9fe612631d8 (patch) | |
tree | 76a873fbbd1af254048bc4b1104c72cd589df34b /Userland/Libraries/LibWeb | |
parent | 1c9c43785d0f3b810e581a6d3267e52f566733b4 (diff) | |
download | serenity-d6cfa34667fe808975279c237d4ac9fe612631d8.zip |
AK: Make URL::m_port an Optional<u16>, Expose raw port getter
Our current way of signalling a missing port with m_port == 0 was
lacking, as 0 is a valid port number in URLs.
Diffstat (limited to 'Userland/Libraries/LibWeb')
5 files changed, 6 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp index e1d5e355f5..a31e1e56e2 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -74,7 +74,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::host_getter) { auto& window = static_cast<WindowObject&>(global_object); auto url = window.impl().associated_document().url(); - return JS::js_string(vm, String::formatted("{}:{}", url.host(), url.port())); + return JS::js_string(vm, String::formatted("{}:{}", url.host(), url.port_or_default())); } JS_DEFINE_NATIVE_FUNCTION(LocationObject::hash_getter) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 0a26a2f214..2cfa9a55c2 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -134,7 +134,7 @@ Origin Document::origin() const { if (!m_url.is_valid()) return {}; - return { m_url.protocol(), m_url.host(), m_url.port() }; + return { m_url.protocol(), m_url.host(), m_url.port_or_default() }; } void Document::set_origin(const Origin& origin) diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp index 2a984e157b..aaf33b3bac 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -165,7 +165,7 @@ bool FrameLoader::load(LoadRequest& request, Type type) AK::URL favicon_url; favicon_url.set_protocol(url.protocol()); favicon_url.set_host(url.host()); - favicon_url.set_port(url.port()); + favicon_url.set_port(url.port_or_default()); favicon_url.set_paths({ "favicon.ico" }); ResourceLoader::the().load( diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp index 45f33e9b8b..fa294bec9b 100644 --- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp @@ -108,8 +108,8 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, con dbgln("ResourceLoader: Failed load of: \"{}\", \033[32;1mError: {}\033[0m, Duration: {}ms", url, error_message, load_time_ms); }; - if (is_port_blocked(url.port())) { - log_failure(request, String::formatted("The port #{} is blocked", url.port())); + if (is_port_blocked(url.port_or_default())) { + log_failure(request, String::formatted("The port #{} is blocked", url.port_or_default())); return; } diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 143fe1c9c6..339e11b0ad 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -171,7 +171,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::send() dbgln("XHR send from {} to {}", m_window->associated_document().url(), request_url); // TODO: Add support for preflight requests to support CORS requests - Origin request_url_origin = Origin(request_url.protocol(), request_url.host(), request_url.port()); + Origin request_url_origin = Origin(request_url.protocol(), request_url.host(), request_url.port_or_default()); bool should_enforce_same_origin_policy = true; if (auto* page = m_window->page()) |