1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:38:11 +00:00

LibWeb: Change Resource's m_encoding to Optional<String>

This modifies the Resource class to use Optional<String> for the
encoding. If the encoding is unknown, the Optional will not have a
value (instead of using the null state of the String class). It also
implements a has_encoding() instance method and modifies the callers
of Resource::encoding() to use the new API.
This commit is contained in:
Max Wipfli 2021-05-12 10:21:00 +02:00 committed by Andreas Kling
parent ce6d6706a6
commit a7681dbeea
3 changed files with 11 additions and 7 deletions

View file

@ -248,11 +248,15 @@ void FrameLoader::resource_did_load()
}
m_redirects_count = 0;
dbgln("I believe this content has MIME type '{}', encoding '{}'", resource()->mime_type(), resource()->encoding());
if (resource()->has_encoding()) {
dbgln("This content has MIME type '{}', encoding '{}'", resource()->mime_type(), resource()->encoding().value());
} else {
dbgln("This content has MIME type '{}', encoding unknown (defaulting to 'utf-8')", resource()->mime_type());
}
auto document = DOM::Document::create();
document->set_url(url);
document->set_encoding(resource()->encoding());
document->set_encoding(resource()->encoding().value_or("utf-8"));
document->set_content_type(resource()->mime_type());
frame().set_document(document);