mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +00:00
LibWeb: Move XMLHttpRequestBodyInit into Fetch
https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit
This commit is contained in:
parent
1bba8589fe
commit
1ace80235b
5 changed files with 30 additions and 11 deletions
19
Userland/Libraries/LibWeb/Fetch/BodyInit.h
Normal file
19
Userland/Libraries/LibWeb/Fetch/BodyInit.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::Fetch {
|
||||
|
||||
// https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit
|
||||
using XMLHttpRequestBodyInit = Variant<JS::Handle<FileAPI::Blob>, JS::Handle<JS::Object>, JS::Handle<URL::URLSearchParams>, String>;
|
||||
|
||||
}
|
5
Userland/Libraries/LibWeb/Fetch/BodyInit.idl
Normal file
5
Userland/Libraries/LibWeb/Fetch/BodyInit.idl
Normal file
|
@ -0,0 +1,5 @@
|
|||
#import <FileAPI/Blob.idl>
|
||||
#import <URL/URLSearchParams.idl>
|
||||
|
||||
// https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit
|
||||
typedef (Blob or BufferSource or URLSearchParams or USVString) XMLHttpRequestBodyInit;
|
|
@ -270,7 +270,7 @@ Optional<StringView> XMLHttpRequest::get_final_encoding() const
|
|||
|
||||
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
|
||||
// FIXME: The parameter 'body_init' should be 'typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit'. For now we just let it be 'XMLHttpRequestBodyInit'.
|
||||
static ErrorOr<Fetch::Infrastructure::BodyWithType> extract_body(XMLHttpRequestBodyInit const& body_init)
|
||||
static ErrorOr<Fetch::Infrastructure::BodyWithType> extract_body(Fetch::XMLHttpRequestBodyInit const& body_init)
|
||||
{
|
||||
// FIXME: 1. Let stream be object if object is a ReadableStream object. Otherwise, let stream be a new ReadableStream, and set up stream.
|
||||
Fetch::Infrastructure::Body::ReadableStreamDummy stream {};
|
||||
|
@ -453,7 +453,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, String
|
|||
}
|
||||
|
||||
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send
|
||||
DOM::ExceptionOr<void> XMLHttpRequest::send(Optional<XMLHttpRequestBodyInit> body)
|
||||
DOM::ExceptionOr<void> XMLHttpRequest::send(Optional<Fetch::XMLHttpRequestBodyInit> body)
|
||||
{
|
||||
if (m_ready_state != ReadyState::Opened)
|
||||
return DOM::InvalidStateError::create(global_object(), "XHR readyState is not OPENED");
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <AK/Weakable.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
#include <LibWeb/Fetch/BodyInit.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Headers.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Statuses.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
|
@ -22,9 +23,6 @@
|
|||
|
||||
namespace Web::XHR {
|
||||
|
||||
// https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit
|
||||
using XMLHttpRequestBodyInit = Variant<JS::Handle<FileAPI::Blob>, JS::Handle<JS::Object>, JS::Handle<URL::URLSearchParams>, String>;
|
||||
|
||||
class XMLHttpRequest final : public XMLHttpRequestEventTarget {
|
||||
WEB_PLATFORM_OBJECT(XMLHttpRequest, XMLHttpRequestEventTarget);
|
||||
|
||||
|
@ -49,7 +47,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(Optional<XMLHttpRequestBodyInit> body);
|
||||
DOM::ExceptionOr<void> send(Optional<Fetch::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; }
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#import <XHR/XMLHttpRequestEventTarget.idl>
|
||||
#import <DOM/EventHandler.idl>
|
||||
#import <FileAPI/Blob.idl>
|
||||
#import <URL/URLSearchParams.idl>
|
||||
|
||||
typedef (Blob or BufferSource or URLSearchParams or USVString) XMLHttpRequestBodyInit;
|
||||
#import <Fetch/BodyInit.idl>
|
||||
#import <XHR/XMLHttpRequestEventTarget.idl>
|
||||
|
||||
enum XMLHttpRequestResponseType {
|
||||
"",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue