mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 00:07:34 +00:00
LibWeb: Combine headers in XMLHttpRequest::set_request_header
This patch adds support for combining header values, in addtion it adds spec comments for readability.
This commit is contained in:
parent
60ff054b02
commit
053bcd4859
1 changed files with 22 additions and 6 deletions
|
@ -411,22 +411,38 @@ static String normalize_header_value(String const& header_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-setrequestheader
|
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-setrequestheader
|
||||||
DOM::ExceptionOr<void> XMLHttpRequest::set_request_header(String const& header, String const& value)
|
DOM::ExceptionOr<void> XMLHttpRequest::set_request_header(String const& name, String const& value)
|
||||||
{
|
{
|
||||||
|
// 1. If this’s state is not opened, then throw an "InvalidStateError" DOMException.
|
||||||
if (m_ready_state != ReadyState::Opened)
|
if (m_ready_state != ReadyState::Opened)
|
||||||
return DOM::InvalidStateError::create("XHR readyState is not OPENED");
|
return DOM::InvalidStateError::create("XHR readyState is not OPENED");
|
||||||
|
|
||||||
|
// 2. If this’s send() flag is set, then throw an "InvalidStateError" DOMException.
|
||||||
if (m_send)
|
if (m_send)
|
||||||
return DOM::InvalidStateError::create("XHR send() flag is already set");
|
return DOM::InvalidStateError::create("XHR send() flag is already set");
|
||||||
|
|
||||||
// FIXME: Check if name matches the name production.
|
// 3. Normalize value.
|
||||||
// FIXME: Check if value matches the value production.
|
auto normalized_value = normalize_header_value(value);
|
||||||
|
|
||||||
if (is_forbidden_header_name(header))
|
// FIXME: 4. If name is not a header name or value is not a header value,
|
||||||
|
// then throw a "SyntaxError" DOMException.
|
||||||
|
|
||||||
|
// 5. If name is a forbidden header name, then return.
|
||||||
|
if (is_forbidden_header_name(name))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// FIXME: Combine
|
// 6. Combine (name, value) in this’s author request headers.
|
||||||
m_request_headers.set(header, normalize_header_value(value));
|
// FIXME: The header name look-up should be case-insensitive.
|
||||||
|
if (m_request_headers.contains(name)) {
|
||||||
|
// 1. If list contains name, then set the value of the first such header to its value,
|
||||||
|
// followed by 0x2C 0x20, followed by value.
|
||||||
|
auto maybe_header_value = m_request_headers.get(name);
|
||||||
|
m_request_headers.set(name, String::formatted("{}, {}", maybe_header_value.release_value(), normalized_value));
|
||||||
|
} else {
|
||||||
|
// 2. Otherwise, append (name, value) to list.
|
||||||
|
m_request_headers.set(name, normalized_value);
|
||||||
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue