diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 8001ac1c700..a92bcb0dc4a 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -369,6 +369,12 @@ WebIDL::ExceptionOr> Document::create_and_initialize(Type type if (auto maybe_last_modified = navigation_params.response->header_list()->get("Last-Modified"sv.bytes()); maybe_last_modified.has_value()) document->m_last_modified = Core::DateTime::parse("%a, %d %b %Y %H:%M:%S %Z"sv, maybe_last_modified.value()); + // NOTE: Non-standard: Pull out the Content-Language header to determine the document's language. + if (auto maybe_http_content_language = navigation_params.response->header_list()->get("Content-Language"sv.bytes()); maybe_http_content_language.has_value()) { + if (auto maybe_content_language = String::from_utf8(maybe_http_content_language.value()); !maybe_content_language.is_error()) + document->m_http_content_language = maybe_content_language.release_value(); + } + // 10. Set window's associated Document to document. window->set_associated_document(*document); diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 4fe28bd9611..40b0cc7c6d2 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -397,6 +397,7 @@ public: Optional const& pragma_set_default_language() const { return m_pragma_set_default_language; } void set_pragma_set_default_language(String language) { m_pragma_set_default_language = move(language); } + Optional const& http_content_language() const { return m_http_content_language; } bool has_encoding() const { return m_encoding.has_value(); } Optional const& encoding() const { return m_encoding; } @@ -923,6 +924,7 @@ private: HTML::DocumentReadyState m_readiness { HTML::DocumentReadyState::Complete }; String m_content_type { "application/xml"_string }; Optional m_pragma_set_default_language; + Optional m_http_content_language; Optional m_encoding; bool m_ready_for_post_load_tasks { false }; diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 6d26890f71b..38f8da5939c 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -3670,6 +3670,10 @@ Optional Element::lang() const } // - If there is no pragma-set default language set, then language information from a higher-level protocol (such as HTTP), + if (document().http_content_language().has_value()) { + return document().http_content_language(); + } + // if any, must be used as the final fallback language instead. // - In the absence of any such language information, and in cases where the higher-level protocol reports multiple languages, // the language of the node is unknown, and the corresponding language tag is the empty string. diff --git a/Tests/LibWeb/Text/expected/HTML/http-content-language.txt b/Tests/LibWeb/Text/expected/HTML/http-content-language.txt new file mode 100644 index 00000000000..a0aba9318ad --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/http-content-language.txt @@ -0,0 +1 @@ +OK \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/HTML/http-content-language.html b/Tests/LibWeb/Text/input/HTML/http-content-language.html new file mode 100644 index 00000000000..57074a753d5 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/http-content-language.html @@ -0,0 +1,38 @@ + + +