Skip to content
Permalink
Browse files
xhr.send(URLSearchParams) should align default Content-Type header fi…
…eld with Chrome and Firefox

https://bugs.webkit.org/show_bug.cgi?id=227477

Patch by Alex Christensen <achristensen@webkit.org> on 2021-06-29
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/xhr/setrequestheader-content-type-expected.txt:

Source/WebCore:

* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::send):
* xml/XMLHttpRequest.h:
* xml/XMLHttpRequest.idl:

LayoutTests:

* platform/ios-wk2/TestExpectations:
* platform/ios/imported/w3c/web-platform-tests/xhr/setrequestheader-content-type-expected.txt: Removed.
* platform/mac-wk1/imported/w3c/web-platform-tests/xhr/setrequestheader-content-type-expected.txt: Added.
* platform/mac/TestExpectations:

Canonical link: https://commits.webkit.org/239245@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279380 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Alex Christensen authored and webkit-commit-queue committed Jun 29, 2021
1 parent 8357f62 commit df0144a4e26904e4b7608adce0f6a9b3c32d5971
Showing 10 changed files with 57 additions and 27 deletions.
@@ -1,3 +1,15 @@
2021-06-29 Alex Christensen <achristensen@webkit.org>

xhr.send(URLSearchParams) should align default Content-Type header field with Chrome and Firefox
https://bugs.webkit.org/show_bug.cgi?id=227477

Reviewed by Chris Dumez.

* platform/ios-wk2/TestExpectations:
* platform/ios/imported/w3c/web-platform-tests/xhr/setrequestheader-content-type-expected.txt: Removed.
* platform/mac-wk1/imported/w3c/web-platform-tests/xhr/setrequestheader-content-type-expected.txt: Added.
* platform/mac/TestExpectations:

2021-06-24 Jer Noble <jer.noble@apple.com>

Loading WebM hangs if server sends only small amount of data
@@ -1,3 +1,12 @@
2021-06-29 Alex Christensen <achristensen@webkit.org>

xhr.send(URLSearchParams) should align default Content-Type header field with Chrome and Firefox
https://bugs.webkit.org/show_bug.cgi?id=227477

Reviewed by Chris Dumez.

* web-platform-tests/xhr/setrequestheader-content-type-expected.txt:

2021-06-29 Martin Robinson <mrobinson@igalia.com>

CSS scroll snap should allow scrolling to the middle of snap areas that overflow the snapport
@@ -12,24 +12,21 @@ PASS HTML Document request respects setRequestHeader("")
PASS HTML Document request has correct default Content-Type of "text/html;charset=UTF-8"
PASS HTML Document request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8
PASS Blob request respects setRequestHeader("") to be specified
FAIL Blob request with unset type sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "Content-Type: \n"
PASS Blob request with unset type sends no Content-Type without setRequestHeader() call
PASS Blob request with unset type keeps setRequestHeader() Content-Type and charset
PASS Blob request with set type respects setRequestHeader("") to be specified
PASS Blob request with set type uses that it for Content-Type unless setRequestHeader()
PASS Blob request with set type keeps setRequestHeader() Content-Type and charset
PASS ArrayBuffer request respects setRequestHeader("")
FAIL ArrayBuffer request sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "Content-Type: application/x-www-form-urlencoded\n"
PASS ArrayBuffer request sends no Content-Type without setRequestHeader() call
PASS ArrayBuffer request keeps setRequestHeader() Content-Type and charset
PASS ArrayBufferView request respects setRequestHeader("")
FAIL ArrayBufferView request sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "Content-Type: application/x-www-form-urlencoded\n"
PASS ArrayBufferView request sends no Content-Type without setRequestHeader() call
PASS ArrayBufferView request keeps setRequestHeader() Content-Type and charset
PASS FormData request respects setRequestHeader("")
PASS FormData request has correct default Content-Type of "multipart/form-data; boundary=_"
PASS FormData request keeps setRequestHeader() Content-Type and charset
PASS URLSearchParams respects setRequestHeader("")
FAIL URLSearchParams request has correct default Content-Type of "application/x-www-form-urlencoded;charset=UTF-8" assert_equals: expected "Content-Type: application/x-www-form-urlencoded;charset=UTF-8\n" but got "Content-Type: text/plain;charset=UTF-8\n"
PASS URLSearchParams request has correct default Content-Type of "application/x-www-form-urlencoded;charset=UTF-8"
PASS URLSearchParams request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8
PASS ReadableStream request respects setRequestHeader("")
FAIL ReadableStream request with under type sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "Content-Type: text/plain;charset=UTF-8\n"
FAIL ReadableStream request keeps setRequestHeader() Content-Type and charset assert_equals: expected "Content-Type: application/xml;charset=ASCII\n" but got "Content-Type: application/xml;charset=UTF-8\n"

@@ -1217,9 +1217,6 @@ webkit.org/b/171985 [ Release ] workers/bomb.html [ Pass Timeout ]

webkit.org/b/175939 [ Debug ] editing/execCommand/forward-delete-read-write-canvas.html [ Skip ]

# <rdar://problem/32826391>
imported/w3c/web-platform-tests/xhr/setrequestheader-content-type.htm [ Failure ]

webkit.org/b/173608 webrtc/video-replace-muted-track.html [ Skip ]

webkit.org/b/187388 animations/needs-layout.html [ Pass ImageOnlyFailure ]
@@ -1,6 +1,3 @@
CONSOLE MESSAGE: ArrayBuffer is deprecated in XMLHttpRequest.send(). Use ArrayBufferView instead.
CONSOLE MESSAGE: ArrayBuffer is deprecated in XMLHttpRequest.send(). Use ArrayBufferView instead.
CONSOLE MESSAGE: ArrayBuffer is deprecated in XMLHttpRequest.send(). Use ArrayBufferView instead.

PASS setRequestHeader("") sends a blank string
PASS setRequestHeader(" ") sends the string " "
@@ -15,23 +12,21 @@ PASS HTML Document request respects setRequestHeader("")
PASS HTML Document request has correct default Content-Type of "text/html;charset=UTF-8"
PASS HTML Document request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8
PASS Blob request respects setRequestHeader("") to be specified
FAIL Blob request with unset type sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "content-type: "
FAIL Blob request with unset type sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "Content-Type: application/x-www-form-urlencoded\n"
PASS Blob request with unset type keeps setRequestHeader() Content-Type and charset
PASS Blob request with set type respects setRequestHeader("") to be specified
PASS Blob request with set type uses that it for Content-Type unless setRequestHeader()
PASS Blob request with set type keeps setRequestHeader() Content-Type and charset
PASS ArrayBuffer request respects setRequestHeader("")
FAIL ArrayBuffer request sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "content-type: application/x-www-form-urlencoded"
FAIL ArrayBuffer request sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "Content-Type: application/x-www-form-urlencoded\n"
PASS ArrayBuffer request keeps setRequestHeader() Content-Type and charset
PASS ArrayBufferView request respects setRequestHeader("")
FAIL ArrayBufferView request sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "content-type: application/x-www-form-urlencoded"
FAIL ArrayBufferView request sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "Content-Type: application/x-www-form-urlencoded\n"
PASS ArrayBufferView request keeps setRequestHeader() Content-Type and charset
PASS FormData request respects setRequestHeader("")
PASS FormData request has correct default Content-Type of "multipart/form-data;boundary=_"
PASS FormData request has correct default Content-Type of "multipart/form-data; boundary=_"
PASS FormData request keeps setRequestHeader() Content-Type and charset
PASS URLSearchParams respects setRequestHeader("")
FAIL URLSearchParams request has correct default Content-Type of "application/x-www-form-urlencoded;charset=UTF-8" assert_equals: expected "content-type: application/x-www-form-urlencoded;charset=utf-8" but got "content-type: text/plain;charset=utf-8"
PASS URLSearchParams request has correct default Content-Type of "application/x-www-form-urlencoded;charset=UTF-8"
PASS URLSearchParams request keeps setRequestHeader() Content-Type, with charset adjusted to UTF-8
PASS ReadableStream request respects setRequestHeader("")
FAIL ReadableStream request with under type sends no Content-Type without setRequestHeader() call assert_equals: expected "" but got "content-type: text/plain;charset=utf-8"
FAIL ReadableStream request keeps setRequestHeader() Content-Type and charset assert_equals: expected "content-type: application/xml;charset=ascii" but got "content-type: application/xml;charset=utf-8"

@@ -1316,9 +1316,6 @@ http/wpt/crypto/rsa-pss-crash.any.worker.html [ Pass ]
fast/dom/HTMLMeterElement/meter-appearances-capacity.html [ Failure ]
fast/dom/HTMLMeterElement/meter-appearances-rating-relevancy.html [ Failure ]

# <rdar://problem/32826391> LayoutTest imported/w3c/web-platform-tests/xhr/setrequestheader-content-type.htm is failing on High Sierra
imported/w3c/web-platform-tests/xhr/setrequestheader-content-type.htm [ Failure ]

# <rdar://problem/32864306> Unskip after bots have CTFontCopyPhysicalFont()
fast/text/system-font-japanese-synthetic-italic.html [ Pass ImageOnlyFailure ]

@@ -1,3 +1,15 @@
2021-06-29 Alex Christensen <achristensen@webkit.org>

xhr.send(URLSearchParams) should align default Content-Type header field with Chrome and Firefox
https://bugs.webkit.org/show_bug.cgi?id=227477

Reviewed by Chris Dumez.

* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::send):
* xml/XMLHttpRequest.h:
* xml/XMLHttpRequest.idl:

2021-06-29 Michael Catanzaro <mcatanzaro@gnome.org>

Fix more -Wreturn-type warnings
@@ -52,6 +52,7 @@
#include "StringAdaptors.h"
#include "TextResourceDecoder.h"
#include "ThreadableLoader.h"
#include "URLSearchParams.h"
#include "XMLDocument.h"
#include "XMLHttpRequestProgressEvent.h"
#include "XMLHttpRequestUpload.h"
@@ -453,6 +454,7 @@ ExceptionOr<void> XMLHttpRequest::send(std::optional<SendTypes>&& sendType)
[this] (const RefPtr<JSC::ArrayBufferView>& arrayBufferView) -> ExceptionOr<void> { return send(*arrayBufferView); },
[this] (const RefPtr<JSC::ArrayBuffer>& arrayBuffer) -> ExceptionOr<void> { return send(*arrayBuffer); },
[this] (const RefPtr<DOMFormData>& formData) -> ExceptionOr<void> { return send(*formData); },
[this] (const RefPtr<URLSearchParams>& searchParams) -> ExceptionOr<void> { return send(*searchParams); },
[this] (const String& string) -> ExceptionOr<void> { return send(string); }
);
}
@@ -536,6 +538,13 @@ ExceptionOr<void> XMLHttpRequest::send(Blob& body)
return createRequest();
}

ExceptionOr<void> XMLHttpRequest::send(const URLSearchParams& params)
{
if (!m_requestHeaders.contains(HTTPHeaderName::ContentType))
m_requestHeaders.set(HTTPHeaderName::ContentType, "application/x-www-form-urlencoded;charset=UTF-8"_s);
return send(params.toString());
}

ExceptionOr<void> XMLHttpRequest::send(DOMFormData& body)
{
if (auto result = prepareToSend())
@@ -47,6 +47,7 @@ class SecurityOrigin;
class SharedBuffer;
class TextResourceDecoder;
class ThreadableLoader;
class URLSearchParams;
class XMLHttpRequestUpload;
struct OwnedString;

@@ -70,7 +71,7 @@ class XMLHttpRequest final : public ActiveDOMObject, public RefCounted<XMLHttpRe
EventTargetInterface eventTargetInterface() const override { return XMLHttpRequestEventTargetInterfaceType; }
ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); }

using SendTypes = Variant<RefPtr<Document>, RefPtr<Blob>, RefPtr<JSC::ArrayBufferView>, RefPtr<JSC::ArrayBuffer>, RefPtr<DOMFormData>, String>;
using SendTypes = Variant<RefPtr<Document>, RefPtr<Blob>, RefPtr<JSC::ArrayBufferView>, RefPtr<JSC::ArrayBuffer>, RefPtr<DOMFormData>, String, RefPtr<URLSearchParams>>;

const URL& url() const { return m_url; }
String statusText() const;
@@ -166,6 +167,7 @@ class XMLHttpRequest final : public ActiveDOMObject, public RefCounted<XMLHttpRe
void notifyIsDone(bool) final;

std::optional<ExceptionOr<void>> prepareToSend();
ExceptionOr<void> send(const URLSearchParams&);
ExceptionOr<void> send(Document&);
ExceptionOr<void> send(const String& = { });
ExceptionOr<void> send(Blob&);
@@ -26,8 +26,8 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

// FIXME: Add URLSearchParams and ReadableStream to the union when supported.
typedef (Blob or BufferSource or DOMFormData or USVString) BodyInit;
// FIXME: Add ReadableStream to the union when supported.
typedef (Blob or BufferSource or DOMFormData or USVString or URLSearchParams) BodyInit;

enum XMLHttpRequestResponseType {
"",

0 comments on commit df0144a

Please sign in to comment.