LibWeb/Fetch: Share a conditional in fetch response handover

See:
- https://github.com/whatwg/fetch/commit/aaada1f
This commit is contained in:
Jamie Mansfield 2024-05-19 13:34:15 +01:00 committed by Andreas Kling
parent 951fbb1837
commit 3438293e7b
Notes: sideshowbarker 2024-07-16 20:31:50 +09:00

View File

@ -596,17 +596,18 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
cache_state = {};
}
// 6. Let responseStatus be 0 if fetchParamss requests mode is "navigate" and responses has-cross-origin-redirects is true; otherwise responses status.
auto response_status = fetch_params.request()->mode() == Infrastructure::Request::Mode::Navigate && response.has_cross_origin_redirects()
? 0
: response.status();
// 6. Let responseStatus be 0.
auto response_status = 0;
// 7. If fetchParamss requests mode is not "navigate" or responses has-cross-origin-redirects is false:
if (fetch_params.request()->mode() != Infrastructure::Request::Mode::Navigate || !response.has_cross_origin_redirects()) {
// 1. Let mimeType be the result of extracting a MIME type from responses header list.
// 1. Set responseStatus to responses status.
response_status = response.status();
// 2. Let mimeType be the result of extracting a MIME type from responses header list.
auto mime_type = response.header_list()->extract_mime_type();
// 2. If mimeType is non-null, then set bodyInfos content type to the result of minimizing a supported MIME type given mimeType.
// 3. If mimeType is non-null, then set bodyInfos content type to the result of minimizing a supported MIME type given mimeType.
if (mime_type.has_value())
body_info.content_type = MimeSniff::minimise_a_supported_mime_type(mime_type.value());
}