mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:48:11 +00:00
LibWeb: Implement XMLHttpRequest.overrideMimeType
This allows you to ignore the Content-Type returned by the server and always parse the content as if it's the given MIME type. This will currently be used for allowing you to override the charset of text responses.
This commit is contained in:
parent
8cfeca5261
commit
4ccade42b7
3 changed files with 24 additions and 0 deletions
|
@ -291,4 +291,21 @@ String XMLHttpRequest::get_all_response_headers() const
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-overridemimetype
|
||||
DOM::ExceptionOr<void> XMLHttpRequest::override_mime_type(String const& mime)
|
||||
{
|
||||
// 1. If this’s state is loading or done, then throw an "InvalidStateError" DOMException.
|
||||
if (m_ready_state == ReadyState::Loading || m_ready_state == ReadyState::Done)
|
||||
return DOM::InvalidStateError::create("Cannot override MIME type when state is Loading or Done.");
|
||||
|
||||
// 2. Set this’s override MIME type to the result of parsing mime.
|
||||
m_override_mime_type = MimeSniff::MimeType::from_string(mime);
|
||||
|
||||
// 3. If this’s override MIME type is failure, then set this’s override MIME type to application/octet-stream.
|
||||
if (!m_override_mime_type.has_value())
|
||||
m_override_mime_type = MimeSniff::MimeType("application"sv, "octet-stream"sv);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue