| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-03-02 22:26:12 +00:00
										 |  |  |  * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org> | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Forward.h>
 | 
					
						
							|  |  |  | #include <LibJS/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2023-02-10 08:29:14 -05:00
										 |  |  | #include <LibJS/Heap/GCPtr.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  | #include <LibWeb/Bindings/PlatformObject.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-07 18:15:52 +00:00
										 |  |  | #include <LibWeb/Bindings/RequestPrototype.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  | #include <LibWeb/Fetch/Body.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Fetch/BodyInit.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Fetch/Headers.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-04 23:45:47 +01:00
										 |  |  | #include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  | #include <LibWeb/Forward.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::Fetch { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://fetch.spec.whatwg.org/#requestinfo
 | 
					
						
							| 
									
										
										
										
											2023-03-02 22:26:12 +00:00
										 |  |  | using RequestInfo = Variant<JS::Handle<Request>, String>; | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | // https://fetch.spec.whatwg.org/#requestinit
 | 
					
						
							|  |  |  | struct RequestInit { | 
					
						
							| 
									
										
										
										
											2023-03-02 22:26:12 +00:00
										 |  |  |     Optional<String> method; | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  |     Optional<HeadersInit> headers; | 
					
						
							|  |  |  |     Optional<Optional<BodyInit>> body; | 
					
						
							| 
									
										
										
										
											2023-03-02 22:26:12 +00:00
										 |  |  |     Optional<String> referrer; | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  |     Optional<Bindings::ReferrerPolicy> referrer_policy; | 
					
						
							|  |  |  |     Optional<Bindings::RequestMode> mode; | 
					
						
							|  |  |  |     Optional<Bindings::RequestCredentials> credentials; | 
					
						
							|  |  |  |     Optional<Bindings::RequestCache> cache; | 
					
						
							|  |  |  |     Optional<Bindings::RequestRedirect> redirect; | 
					
						
							| 
									
										
										
										
											2023-03-02 22:26:12 +00:00
										 |  |  |     Optional<String> integrity; | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  |     Optional<bool> keepalive; | 
					
						
							|  |  |  |     Optional<JS::GCPtr<DOM::AbortSignal>> signal; | 
					
						
							|  |  |  |     Optional<Bindings::RequestDuplex> duplex; | 
					
						
							|  |  |  |     Optional<JS::Value> window; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://infra.spec.whatwg.org/#map-is-empty
 | 
					
						
							|  |  |  |     bool is_empty() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return !(method.has_value() | 
					
						
							|  |  |  |             || headers.has_value() | 
					
						
							|  |  |  |             || body.has_value() | 
					
						
							|  |  |  |             || referrer.has_value() | 
					
						
							|  |  |  |             || referrer_policy.has_value() | 
					
						
							|  |  |  |             || mode.has_value() | 
					
						
							|  |  |  |             || credentials.has_value() | 
					
						
							|  |  |  |             || cache.has_value() | 
					
						
							|  |  |  |             || redirect.has_value() | 
					
						
							|  |  |  |             || integrity.has_value() | 
					
						
							|  |  |  |             || keepalive.has_value() | 
					
						
							|  |  |  |             || signal.has_value() | 
					
						
							|  |  |  |             || duplex.has_value() | 
					
						
							|  |  |  |             || window.has_value()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://fetch.spec.whatwg.org/#request
 | 
					
						
							|  |  |  | class Request final | 
					
						
							|  |  |  |     : public Bindings::PlatformObject | 
					
						
							|  |  |  |     , public BodyMixin { | 
					
						
							|  |  |  |     WEB_PLATFORM_OBJECT(Request, Bindings::PlatformObject); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(Request); | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-03-26 07:45:11 +00:00
										 |  |  |     [[nodiscard]] static JS::NonnullGCPtr<Request> create(JS::Realm&, JS::NonnullGCPtr<Infrastructure::Request>, Headers::Guard, JS::NonnullGCPtr<DOM::AbortSignal>); | 
					
						
							| 
									
										
										
										
											2022-09-25 18:08:29 -06:00
										 |  |  |     static WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> construct_impl(JS::Realm&, RequestInfo const& input, RequestInit const& init = {}); | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual ~Request() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // ^BodyMixin
 | 
					
						
							| 
									
										
										
										
											2024-04-27 10:15:01 -04:00
										 |  |  |     virtual Optional<MimeSniff::MimeType> mime_type_impl() const override; | 
					
						
							| 
									
										
										
										
											2023-08-18 19:38:13 +02:00
										 |  |  |     virtual JS::GCPtr<Infrastructure::Body> body_impl() override; | 
					
						
							|  |  |  |     virtual JS::GCPtr<Infrastructure::Body const> body_impl() const override; | 
					
						
							| 
									
										
										
										
											2023-02-28 18:12:44 +00:00
										 |  |  |     virtual Bindings::PlatformObject& as_platform_object() override { return *this; } | 
					
						
							|  |  |  |     virtual Bindings::PlatformObject const& as_platform_object() const override { return *this; } | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 01:52:07 +00:00
										 |  |  |     [[nodiscard]] JS::NonnullGCPtr<Infrastructure::Request> request() const { return m_request; } | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // JS API functions
 | 
					
						
							| 
									
										
										
										
											2024-04-27 10:31:50 -04:00
										 |  |  |     [[nodiscard]] String method() const; | 
					
						
							|  |  |  |     [[nodiscard]] String url() const; | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  |     [[nodiscard]] JS::NonnullGCPtr<Headers> headers() const; | 
					
						
							|  |  |  |     [[nodiscard]] Bindings::RequestDestination destination() const; | 
					
						
							| 
									
										
										
										
											2024-04-27 10:31:50 -04:00
										 |  |  |     [[nodiscard]] String referrer() const; | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  |     [[nodiscard]] Bindings::ReferrerPolicy referrer_policy() const; | 
					
						
							|  |  |  |     [[nodiscard]] Bindings::RequestMode mode() const; | 
					
						
							|  |  |  |     [[nodiscard]] Bindings::RequestCredentials credentials() const; | 
					
						
							|  |  |  |     [[nodiscard]] Bindings::RequestCache cache() const; | 
					
						
							|  |  |  |     [[nodiscard]] Bindings::RequestRedirect redirect() const; | 
					
						
							| 
									
										
										
										
											2023-03-02 23:26:35 +00:00
										 |  |  |     [[nodiscard]] String integrity() const; | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  |     [[nodiscard]] bool keepalive() const; | 
					
						
							|  |  |  |     [[nodiscard]] bool is_reload_navigation() const; | 
					
						
							|  |  |  |     [[nodiscard]] bool is_history_navigation() const; | 
					
						
							|  |  |  |     [[nodiscard]] JS::NonnullGCPtr<DOM::AbortSignal> signal() const; | 
					
						
							| 
									
										
										
										
											2022-10-15 00:41:10 +02:00
										 |  |  |     [[nodiscard]] Bindings::RequestDuplex duplex() const; | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> clone() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-10-30 01:52:07 +00:00
										 |  |  |     Request(JS::Realm&, JS::NonnullGCPtr<Infrastructure::Request>); | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://fetch.spec.whatwg.org/#concept-request-request
 | 
					
						
							|  |  |  |     // A Request object has an associated request (a request).
 | 
					
						
							| 
									
										
										
										
											2022-10-30 01:52:07 +00:00
										 |  |  |     JS::NonnullGCPtr<Infrastructure::Request> m_request; | 
					
						
							| 
									
										
										
										
											2022-09-25 19:33:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // https://fetch.spec.whatwg.org/#request-headers
 | 
					
						
							|  |  |  |     // A Request object also has an associated headers (null or a Headers object), initially null.
 | 
					
						
							|  |  |  |     JS::GCPtr<Headers> m_headers; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://fetch.spec.whatwg.org/#request-signal
 | 
					
						
							|  |  |  |     // A Request object has an associated signal (null or an AbortSignal object), initially null.
 | 
					
						
							|  |  |  |     JS::GCPtr<DOM::AbortSignal> m_signal; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |