mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 16:16:43 +00:00
LibWeb: Implement formData() method steps for x-www-form-urlencoded
The Response interface of the Fetch API can now parse form urlencoded bodies when Content-Type is set to 'application/x-www-form-urlencoded'.
This commit is contained in:
parent
7047fcf761
commit
b8fa572c67
Notes:
github-actions[bot]
2024-07-23 07:03:35 +00:00
Author: https://github.com/kennethmyhra
Commit: b8fa572c67
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/763
5 changed files with 46 additions and 6 deletions
|
@ -15,6 +15,7 @@
|
|||
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||||
#include <LibWeb/Bindings/HostDefined.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/DOMURL/URLSearchParams.h>
|
||||
#include <LibWeb/Fetch/Body.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
|
||||
#include <LibWeb/FileAPI/Blob.h>
|
||||
|
@ -23,6 +24,7 @@
|
|||
#include <LibWeb/MimeSniff/MimeType.h>
|
||||
#include <LibWeb/Streams/ReadableStream.h>
|
||||
#include <LibWeb/WebIDL/Promise.h>
|
||||
#include <LibWeb/XHR/FormData.h>
|
||||
|
||||
namespace Web::Fetch {
|
||||
|
||||
|
@ -143,10 +145,15 @@ WebIDL::ExceptionOr<JS::Value> package_data(JS::Realm& realm, ByteBuffer bytes,
|
|||
}
|
||||
// Otherwise, if mimeType’s essence is "application/x-www-form-urlencoded", then:
|
||||
else if (mime_type.has_value() && mime_type->essence() == "application/x-www-form-urlencoded"sv) {
|
||||
// FIXME: 1. Let entries be the result of parsing bytes.
|
||||
// FIXME: 2. If entries is failure, then throw a TypeError.
|
||||
// FIXME: 3. Return a new FormData object whose entry list is entries.
|
||||
return JS::js_null();
|
||||
// 1. Let entries be the result of parsing bytes.
|
||||
auto entries = DOMURL::url_decode(StringView { bytes });
|
||||
|
||||
// 2. If entries is failure, then throw a TypeError.
|
||||
if (entries.is_error())
|
||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, entries.error().string_literal() };
|
||||
|
||||
// 3. Return a new FormData object whose entry list is entries.
|
||||
return TRY(XHR::FormData::create(realm, entries.release_value()));
|
||||
}
|
||||
// Otherwise, throw a TypeError.
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue