|
@@ -21,6 +21,12 @@ ImageLoader::ImageLoader(DOM::Element& owner_element)
|
|
|
}
|
|
|
|
|
|
void ImageLoader::load(const AK::URL& url)
|
|
|
+{
|
|
|
+ m_redirects_count = 0;
|
|
|
+ load_without_resetting_redirect_counter(url);
|
|
|
+}
|
|
|
+
|
|
|
+void ImageLoader::load_without_resetting_redirect_counter(AK::URL const& url)
|
|
|
{
|
|
|
m_loading_state = LoadingState::Loading;
|
|
|
|
|
@@ -45,6 +51,25 @@ void ImageLoader::resource_did_load()
|
|
|
{
|
|
|
VERIFY(resource());
|
|
|
|
|
|
+ // For 3xx (Redirection) responses, the Location value refers to the preferred target resource for automatically redirecting the request.
|
|
|
+ auto status_code = resource()->status_code();
|
|
|
+ if (status_code.has_value() && *status_code >= 300 && *status_code <= 399) {
|
|
|
+ auto location = resource()->response_headers().get("Location");
|
|
|
+ if (location.has_value()) {
|
|
|
+ if (m_redirects_count > maximum_redirects_allowed) {
|
|
|
+ m_redirects_count = 0;
|
|
|
+ m_loading_state = LoadingState::Failed;
|
|
|
+ if (on_fail)
|
|
|
+ on_fail();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ m_redirects_count++;
|
|
|
+ load_without_resetting_redirect_counter(resource()->url().complete_url(location.value()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ m_redirects_count = 0;
|
|
|
+
|
|
|
if (!resource()->mime_type().starts_with("image/")) {
|
|
|
m_loading_state = LoadingState::Failed;
|
|
|
if (on_fail)
|