| Index: Source/core/xml/XMLHttpRequest.cpp
|
| diff --git a/Source/core/xml/XMLHttpRequest.cpp b/Source/core/xml/XMLHttpRequest.cpp
|
| index 2a585245b23d0b254675ac78d083214150baeb33..70378bb5f9a0d3bb76b8b9e33b11cb657ee1e385 100644
|
| --- a/Source/core/xml/XMLHttpRequest.cpp
|
| +++ b/Source/core/xml/XMLHttpRequest.cpp
|
| @@ -657,6 +657,8 @@ void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState)
|
| if (!initSend(exceptionState))
|
| return;
|
|
|
| + RefPtr<FormData> httpBody;
|
| +
|
| if (areMethodAndURLValidForSend()) {
|
| if (getRequestHeader("Content-Type").isEmpty()) {
|
| // FIXME: this should include the charset used for encoding.
|
| @@ -668,12 +670,12 @@ void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState)
|
| String body = createMarkup(document);
|
|
|
| // FIXME: This should use value of document.inputEncoding to determine the encoding to use.
|
| - m_requestEntityBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesForUnencodables));
|
| + httpBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesForUnencodables));
|
| if (m_upload)
|
| - m_requestEntityBody->setAlwaysStream(true);
|
| + httpBody->setAlwaysStream(true);
|
| }
|
|
|
| - createRequest(exceptionState);
|
| + createRequest(httpBody.release(), exceptionState);
|
| }
|
|
|
| void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState)
|
| @@ -683,6 +685,8 @@ void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState)
|
| if (!initSend(exceptionState))
|
| return;
|
|
|
| + RefPtr<FormData> httpBody;
|
| +
|
| if (!body.isNull() && areMethodAndURLValidForSend()) {
|
| String contentType = getRequestHeader("Content-Type");
|
| if (contentType.isEmpty()) {
|
| @@ -692,12 +696,12 @@ void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState)
|
| m_requestHeaders.set("Content-Type", AtomicString(contentType));
|
| }
|
|
|
| - m_requestEntityBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesForUnencodables));
|
| + httpBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesForUnencodables));
|
| if (m_upload)
|
| - m_requestEntityBody->setAlwaysStream(true);
|
| + httpBody->setAlwaysStream(true);
|
| }
|
|
|
| - createRequest(exceptionState);
|
| + createRequest(httpBody.release(), exceptionState);
|
| }
|
|
|
| void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState)
|
| @@ -707,6 +711,8 @@ void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState)
|
| if (!initSend(exceptionState))
|
| return;
|
|
|
| + RefPtr<FormData> httpBody;
|
| +
|
| if (areMethodAndURLValidForSend()) {
|
| if (getRequestHeader("Content-Type").isEmpty()) {
|
| const String& blobType = body->type();
|
| @@ -719,21 +725,21 @@ void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState)
|
| }
|
|
|
| // FIXME: add support for uploading bundles.
|
| - m_requestEntityBody = FormData::create();
|
| + httpBody = FormData::create();
|
| if (body->hasBackingFile()) {
|
| File* file = toFile(body);
|
| if (!file->path().isEmpty())
|
| - m_requestEntityBody->appendFile(file->path());
|
| + httpBody->appendFile(file->path());
|
| else if (!file->fileSystemURL().isEmpty())
|
| - m_requestEntityBody->appendFileSystemURL(file->fileSystemURL());
|
| + httpBody->appendFileSystemURL(file->fileSystemURL());
|
| else
|
| ASSERT_NOT_REACHED();
|
| } else {
|
| - m_requestEntityBody->appendBlob(body->uuid(), body->blobDataHandle());
|
| + httpBody->appendBlob(body->uuid(), body->blobDataHandle());
|
| }
|
| }
|
|
|
| - createRequest(exceptionState);
|
| + createRequest(httpBody.release(), exceptionState);
|
| }
|
|
|
| void XMLHttpRequest::send(DOMFormData* body, ExceptionState& exceptionState)
|
| @@ -743,16 +749,18 @@ void XMLHttpRequest::send(DOMFormData* body, ExceptionState& exceptionState)
|
| if (!initSend(exceptionState))
|
| return;
|
|
|
| + RefPtr<FormData> httpBody;
|
| +
|
| if (areMethodAndURLValidForSend()) {
|
| - m_requestEntityBody = body->createMultiPartFormData(body->encoding());
|
| + httpBody = body->createMultiPartFormData(body->encoding());
|
|
|
| if (getRequestHeader("Content-Type").isEmpty()) {
|
| - AtomicString contentType = AtomicString("multipart/form-data; boundary=", AtomicString::ConstructFromLiteral) + m_requestEntityBody->boundary().data();
|
| + AtomicString contentType = AtomicString("multipart/form-data; boundary=", AtomicString::ConstructFromLiteral) + httpBody->boundary().data();
|
| setRequestHeaderInternal("Content-Type", contentType);
|
| }
|
| }
|
|
|
| - createRequest(exceptionState);
|
| + createRequest(httpBody.release(), exceptionState);
|
| }
|
|
|
| void XMLHttpRequest::send(ArrayBuffer* body, ExceptionState& exceptionState)
|
| @@ -781,23 +789,24 @@ void XMLHttpRequest::sendBytesData(const void* data, size_t length, ExceptionSta
|
| if (!initSend(exceptionState))
|
| return;
|
|
|
| + RefPtr<FormData> httpBody;
|
| +
|
| if (areMethodAndURLValidForSend()) {
|
| - m_requestEntityBody = FormData::create(data, length);
|
| + httpBody = FormData::create(data, length);
|
| if (m_upload)
|
| - m_requestEntityBody->setAlwaysStream(true);
|
| + httpBody->setAlwaysStream(true);
|
| }
|
|
|
| - createRequest(exceptionState);
|
| + createRequest(httpBody.release(), exceptionState);
|
| }
|
|
|
| void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, ExceptionState& exceptionState)
|
| {
|
| - m_requestEntityBody = formData ? formData->deepCopy() : nullptr;
|
| - createRequest(exceptionState);
|
| + createRequest(formData ? formData->deepCopy() : nullptr, exceptionState);
|
| m_exceptionCode = exceptionState.code();
|
| }
|
|
|
| -void XMLHttpRequest::createRequest(ExceptionState& exceptionState)
|
| +void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState& exceptionState)
|
| {
|
| // Only GET request is supported for blob URL.
|
| if (m_url.protocolIs("blob") && m_method != "GET") {
|
| @@ -811,7 +820,7 @@ void XMLHttpRequest::createRequest(ExceptionState& exceptionState)
|
| bool uploadEvents = false;
|
| if (m_async) {
|
| dispatchProgressEvent(EventTypeNames::loadstart, 0, 0);
|
| - if (m_requestEntityBody && m_upload) {
|
| + if (httpBody && m_upload) {
|
| uploadEvents = m_upload->hasEventListeners();
|
| m_upload->dispatchEvent(XMLHttpRequestProgressEvent::create(EventTypeNames::loadstart));
|
| }
|
| @@ -830,12 +839,12 @@ void XMLHttpRequest::createRequest(ExceptionState& exceptionState)
|
| request.setHTTPMethod(m_method);
|
| request.setTargetType(ResourceRequest::TargetIsXHR);
|
|
|
| - InspectorInstrumentation::willLoadXHR(&executionContext, this, this, m_method, m_url, m_async, m_requestEntityBody ? m_requestEntityBody->deepCopy() : nullptr, m_requestHeaders, m_includeCredentials);
|
| + InspectorInstrumentation::willLoadXHR(&executionContext, this, this, m_method, m_url, m_async, httpBody ? httpBody->deepCopy() : nullptr, m_requestHeaders, m_includeCredentials);
|
|
|
| - if (m_requestEntityBody) {
|
| + if (httpBody) {
|
| ASSERT(m_method != "GET");
|
| ASSERT(m_method != "HEAD");
|
| - request.setHTTPBody(m_requestEntityBody.release());
|
| + request.setHTTPBody(httpBody);
|
| }
|
|
|
| if (m_requestHeaders.size() > 0)
|
| @@ -998,7 +1007,6 @@ void XMLHttpRequest::clearResponse()
|
| void XMLHttpRequest::clearRequest()
|
| {
|
| m_requestHeaders.clear();
|
| - m_requestEntityBody = nullptr;
|
| }
|
|
|
| void XMLHttpRequest::handleDidFailGeneric()
|
|
|