mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 14:37:43 +00:00
LibWeb: Allow passing a (String) body to XMLHttpRequest.send()
This patch implements the simplest form of send(body): strings.
This commit is contained in:
parent
194dc8b25d
commit
ed5c807c99
3 changed files with 5 additions and 3 deletions
|
@ -157,7 +157,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::open(const String& method, const String&
|
|||
}
|
||||
|
||||
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send
|
||||
DOM::ExceptionOr<void> XMLHttpRequest::send()
|
||||
DOM::ExceptionOr<void> XMLHttpRequest::send(String const& body)
|
||||
{
|
||||
if (m_ready_state != ReadyState::Opened)
|
||||
return DOM::InvalidStateError::create("XHR readyState is not OPENED");
|
||||
|
@ -188,6 +188,8 @@ DOM::ExceptionOr<void> XMLHttpRequest::send()
|
|||
|
||||
auto request = LoadRequest::create_for_url_on_page(request_url, m_window->page());
|
||||
request.set_method(m_method);
|
||||
if (!body.is_null())
|
||||
request.set_body(body.to_byte_buffer());
|
||||
for (auto& it : m_request_headers)
|
||||
request.set_header(it.key, it.value);
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
String response_text() const;
|
||||
|
||||
DOM::ExceptionOr<void> open(const String& method, const String& url);
|
||||
DOM::ExceptionOr<void> send();
|
||||
DOM::ExceptionOr<void> send(String const& body);
|
||||
|
||||
DOM::ExceptionOr<void> set_request_header(const String& header, const String& value);
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget {
|
|||
|
||||
undefined open(DOMString method, DOMString url);
|
||||
undefined setRequestHeader(DOMString name, DOMString value);
|
||||
undefined send();
|
||||
undefined send(optional USVString body = {});
|
||||
|
||||
ByteString? getResponseHeader(ByteString name);
|
||||
ByteString getAllResponseHeaders();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue