1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 22:08:12 +00:00

LibWeb: Add support for XMLHttpRequest request headers

Implement XMLHttpRequest.setRequestHeader() and include the headers in
the outgoing HTTP request.
This commit is contained in:
Andreas Kling 2021-01-18 14:01:05 +01:00
parent 0639e77898
commit c99e35485a
4 changed files with 33 additions and 1 deletions

View file

@ -63,10 +63,16 @@ String XMLHttpRequest::response_text() const
return String::copy(m_response);
}
void XMLHttpRequest::set_request_header(const String& header, const String& value)
{
m_request_headers.set(header, value);
}
void XMLHttpRequest::open(const String& method, const String& url)
{
m_method = method;
m_url = url;
m_request_headers.clear();
set_ready_state(ReadyState::Opened);
}
@ -88,10 +94,15 @@ void XMLHttpRequest::send()
return;
}
LoadRequest request;
request.set_url(m_window->document().complete_url(m_url));
for (auto& it : m_request_headers)
request.set_header(it.key, it.value);
// FIXME: in order to properly set ReadyState::HeadersReceived and ReadyState::Loading,
// we need to make ResourceLoader give us more detailed updates than just "done" and "error".
ResourceLoader::the().load(
m_window->document().complete_url(m_url),
request,
[weak_this = make_weak_ptr()](auto data, auto&) {
if (!weak_this)
return;