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.
This commit is contained in:
Linus Groh 2022-10-24 18:51:25 +01:00
parent 8f8fcfee1a
commit 7e7def71c1
Notes: sideshowbarker 2024-07-17 09:41:18 +09:00

View file

@ -44,23 +44,26 @@ NonnullRefPtr<Response> 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<AK::URL const&> Response::url() const
{
// A response has an associated URL. It is a pointer to the last URL in responses URL list and null if responses 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<Optional<AK::URL>> Response::location_url(Optional<String> 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 responses 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<AK::URL> {};
// FIXME: 2. Let location be the result of extracting header list values given `Location` and responses header list.