mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
LibWeb: Support for Content-Language
HTTP header
This commit is contained in:
parent
dda1573746
commit
c9edb6ffc4
Notes:
github-actions[bot]
2025-02-19 10:54:32 +00:00
Author: https://github.com/pbrw Commit: https://github.com/LadybirdBrowser/ladybird/commit/c9edb6ffc44 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3255 Reviewed-by: https://github.com/shannonbooth ✅ Reviewed-by: https://github.com/tcl3 ✅
5 changed files with 51 additions and 0 deletions
|
@ -369,6 +369,12 @@ WebIDL::ExceptionOr<GC::Ref<Document>> 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);
|
||||
|
||||
|
|
|
@ -397,6 +397,7 @@ public:
|
|||
|
||||
Optional<String> 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<String> const& http_content_language() const { return m_http_content_language; }
|
||||
|
||||
bool has_encoding() const { return m_encoding.has_value(); }
|
||||
Optional<String> 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<String> m_pragma_set_default_language;
|
||||
Optional<String> m_http_content_language;
|
||||
Optional<String> m_encoding;
|
||||
|
||||
bool m_ready_for_post_load_tasks { false };
|
||||
|
|
|
@ -3670,6 +3670,10 @@ Optional<String> 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.
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
OK
|
38
Tests/LibWeb/Text/input/HTML/http-content-language.html
Normal file
38
Tests/LibWeb/Text/input/HTML/http-content-language.html
Normal file
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
asyncTest(async (done) => {
|
||||
const httpServer = httpTestServer();
|
||||
const url = await httpServer.createEcho("GET", "/http-content-language-test", {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Expose-Headers": "Content-Language",
|
||||
"Content-Language": "ko",
|
||||
},
|
||||
body: `
|
||||
<style>
|
||||
div { width: 50px; }
|
||||
#box:lang(ko) { width: 100px; }
|
||||
</style>
|
||||
<body><div id="box">TEST</div></body>
|
||||
<script>
|
||||
if (document.getElementById("box").offsetWidth == 100) {
|
||||
parent.postMessage("OK", "*")
|
||||
} else {
|
||||
parent.postMessage("FAIL", "*")
|
||||
}
|
||||
<\/script>`,
|
||||
});
|
||||
|
||||
const frame = document.createElement('iframe');
|
||||
frame.src = url;
|
||||
|
||||
addEventListener("message", (event) => {
|
||||
println(event.data);
|
||||
done();
|
||||
}, false);
|
||||
|
||||
document.body.appendChild(frame);
|
||||
});
|
||||
</script>
|
Loading…
Add table
Reference in a new issue