mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
LibWeb: Add URLSearchParams as part of union type for XHR::send()
This patch adds support for URLSearchParams to XHR::send() and introduces the union type XMLHttpRequestBodyInit. XHR::send() now has support for String and URLSearchParams.
This commit is contained in:
parent
bd74db157a
commit
247951e09c
4 changed files with 40 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -15,12 +16,15 @@
|
|||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
#include <LibWeb/MimeSniff/MimeType.h>
|
||||
#include <LibWeb/URL/URLSearchParams.h>
|
||||
#include <LibWeb/XHR/XMLHttpRequestEventTarget.h>
|
||||
|
||||
namespace Web::XHR {
|
||||
|
||||
static constexpr Array<u8, 4> http_whitespace_bytes = { '\t', '\n', '\r', ' ' };
|
||||
|
||||
using XMLHttpRequestBodyInit = Variant<NonnullRefPtr<URL::URLSearchParams>, String>;
|
||||
|
||||
class XMLHttpRequest final
|
||||
: public RefCounted<XMLHttpRequest>
|
||||
, public Weakable<XMLHttpRequest>
|
||||
|
@ -34,6 +38,11 @@ public:
|
|||
Done = 4,
|
||||
};
|
||||
|
||||
struct BodyWithType {
|
||||
ByteBuffer body;
|
||||
String type;
|
||||
};
|
||||
|
||||
using WrapperType = Bindings::XMLHttpRequestWrapper;
|
||||
|
||||
static NonnullRefPtr<XMLHttpRequest> create(HTML::Window& window)
|
||||
|
@ -58,7 +67,7 @@ public:
|
|||
|
||||
DOM::ExceptionOr<void> open(String const& method, String const& url);
|
||||
DOM::ExceptionOr<void> open(String const& method, String const& url, bool async, String const& username = {}, String const& password = {});
|
||||
DOM::ExceptionOr<void> send(String body);
|
||||
DOM::ExceptionOr<void> send(Optional<XMLHttpRequestBodyInit> body);
|
||||
|
||||
DOM::ExceptionOr<void> set_request_header(String const& header, String const& value);
|
||||
void set_response_type(Bindings::XMLHttpRequestResponseType type) { m_response_type = type; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue