From 7e7def71c19a526533c34d8da4cf4394a7a2004d Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 24 Oct 2022 18:51:25 +0100 Subject: [PATCH] LibWeb: Use getters instead of direct member access in Response methods This fixes the behavior of those methods for FilteredResponse subclasses as those only override the getter methods, not their private members. --- .../LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp index d523e35f69..398f7fed19 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp @@ -44,23 +44,26 @@ NonnullRefPtr Response::network_error() bool Response::is_aborted_network_error() const { // A response whose type is "error" and aborted flag is set is known as an aborted network error. - return m_type == Type::Error && m_aborted; + // NOTE: We have to use the virtual getter here to not bypass filtered responses. + return type() == Type::Error && aborted(); } // https://fetch.spec.whatwg.org/#concept-network-error bool Response::is_network_error() const { // A response whose type is "error" is known as a network error. - return m_type == Type::Error; + // NOTE: We have to use the virtual getter here to not bypass filtered responses. + return type() == Type::Error; } // https://fetch.spec.whatwg.org/#concept-response-url Optional Response::url() const { // A response has an associated URL. It is a pointer to the last URL in response’s URL list and null if response’s URL list is empty. - if (m_url_list.is_empty()) + // NOTE: We have to use the virtual getter here to not bypass filtered responses. + if (url_list().is_empty()) return {}; - return m_url_list.last(); + return url_list().last(); } // https://fetch.spec.whatwg.org/#concept-response-location-url @@ -69,7 +72,8 @@ ErrorOr> Response::location_url(Optional const& reques // The location URL of a response response, given null or an ASCII string requestFragment, is the value returned by the following steps. They return null, failure, or a URL. // 1. If response’s status is not a redirect status, then return null. - if (!is_redirect_status(m_status)) + // NOTE: We have to use the virtual getter here to not bypass filtered responses. + if (!is_redirect_status(status())) return Optional {}; // FIXME: 2. Let location be the result of extracting header list values given `Location` and response’s header list.