mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 03:47:34 +00:00
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.
This commit is contained in:
parent
1c9c43785d
commit
d6cfa34667
15 changed files with 42 additions and 41 deletions
|
@ -45,7 +45,7 @@ void GeminiJob::start()
|
|||
if (on_certificate_requested)
|
||||
on_certificate_requested(*this);
|
||||
};
|
||||
bool success = ((TLS::TLSv12&)*m_socket).connect(m_request.url().host(), m_request.url().port());
|
||||
bool success = ((TLS::TLSv12&)*m_socket).connect(m_request.url().host(), m_request.url().port_or_default());
|
||||
if (!success) {
|
||||
deferred_invoke([this] {
|
||||
return did_fail(Core::NetworkJob::Error::ConnectionFailed);
|
||||
|
|
|
@ -26,7 +26,7 @@ void HttpJob::start()
|
|||
did_fail(Core::NetworkJob::Error::ConnectionFailed);
|
||||
});
|
||||
};
|
||||
bool success = m_socket->connect(m_request.url().host(), m_request.url().port());
|
||||
bool success = m_socket->connect(m_request.url().host(), m_request.url().port_or_default());
|
||||
if (!success) {
|
||||
deferred_invoke([this] {
|
||||
return did_fail(Core::NetworkJob::Error::ConnectionFailed);
|
||||
|
|
|
@ -46,7 +46,7 @@ void HttpsJob::start()
|
|||
if (on_certificate_requested)
|
||||
on_certificate_requested(*this);
|
||||
};
|
||||
bool success = ((TLS::TLSv12&)*m_socket).connect(m_request.url().host(), m_request.url().port());
|
||||
bool success = ((TLS::TLSv12&)*m_socket).connect(m_request.url().host(), m_request.url().port_or_default());
|
||||
if (!success) {
|
||||
deferred_invoke([this] {
|
||||
return did_fail(Core::NetworkJob::Error::ConnectionFailed);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -34,7 +34,7 @@ void TCPWebSocketConnectionImpl::connect(ConnectionInfo const& connection)
|
|||
m_socket->on_connected = [this] {
|
||||
on_connected();
|
||||
};
|
||||
bool success = m_socket->connect(connection.url().host(), connection.url().port());
|
||||
bool success = m_socket->connect(connection.url().host(), connection.url().port_or_default());
|
||||
if (!success) {
|
||||
deferred_invoke([this] {
|
||||
on_connection_error();
|
||||
|
|
|
@ -42,7 +42,7 @@ void TLSv12WebSocketConnectionImpl::connect(ConnectionInfo const& connection)
|
|||
m_socket->on_tls_certificate_request = [](auto&) {
|
||||
// FIXME : Once we handle TLS certificate requests, handle it here as well.
|
||||
};
|
||||
bool success = m_socket->connect(connection.url().host(), connection.url().port());
|
||||
bool success = m_socket->connect(connection.url().host(), connection.url().port_or_default());
|
||||
if (!success) {
|
||||
deferred_invoke([this] {
|
||||
on_connection_error();
|
||||
|
|
|
@ -151,10 +151,10 @@ void WebSocket::send_client_handshake()
|
|||
// 4. Host
|
||||
auto url = m_connection.url();
|
||||
builder.appendff("Host: {}", url.host());
|
||||
if (!m_connection.is_secure() && url.port() != 80)
|
||||
builder.appendff(":{}", url.port());
|
||||
else if (m_connection.is_secure() && url.port() != 443)
|
||||
builder.appendff(":{}", url.port());
|
||||
if (!m_connection.is_secure() && url.port_or_default() != 80)
|
||||
builder.appendff(":{}", url.port_or_default());
|
||||
else if (m_connection.is_secure() && url.port_or_default() != 443)
|
||||
builder.appendff(":{}", url.port_or_default());
|
||||
builder.append("\r\n");
|
||||
|
||||
// 5. and 6. Connection Upgrade
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue