void XMLHttpRequest::send(const String& body, ExceptionCode& ec) { if (!initSend(ec)) return; if (!body.isNull() && m_method != "GET" && m_method != "HEAD" && m_url.protocolInHTTPFamily()) { String contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { #if ENABLE(DASHBOARD_SUPPORT) if (usesDashboardBackwardCompatibilityMode()) setRequestHeaderInternal("Content-Type", "application/x-www-form-urlencoded"); else #endif setRequestHeaderInternal("Content-Type", "application/xml"); } else { replaceCharsetInMediaType(contentType, "UTF-8"); m_requestHeaders.set("Content-Type", contentType); } m_requestEntityBody = FormData::create(UTF8Encoding().encode(body.characters(), body.length(), EntitiesForUnencodables)); if (m_upload) m_requestEntityBody->setAlwaysStream(true); } createRequest(ec); }
void XMLHttpRequest::send(const String& body, ExceptionCode& ec) { if (!initSend(ec)) return; // 03/31/2011 - abaldeva : Change the request to execute for any protocol except file. This allows for using XmlHttpRequest object with Custom // protocols. //if (!body.isNull() && m_method != "GET" && m_method != "HEAD" && (m_url.protocolIs("http") || m_url.protocolIs("https"))) { if (!body.isNull() && m_method != "GET" && m_method != "HEAD" && !m_url.protocolIs("file")) { String contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { #if ENABLE(DASHBOARD_SUPPORT) Settings* settings = m_doc->settings(); if (settings && settings->usesDashboardBackwardCompatibilityMode()) setRequestHeaderInternal("Content-Type", "application/x-www-form-urlencoded"); else #endif setRequestHeaderInternal("Content-Type", "application/xml"); } m_requestEntityBody = FormData::create(UTF8Encoding().encode(body.characters(), body.length(), EntitiesForUnencodables)); } createRequest(ec); }
void XMLHttpRequest::send(Document* document, ExceptionCode& ec) { ASSERT(document); if (!initSend(ec)) return; if (m_method != "GET" && m_method != "HEAD" && m_url.protocolInHTTPFamily()) { String contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { #if ENABLE(DASHBOARD_SUPPORT) if (usesDashboardBackwardCompatibilityMode()) setRequestHeaderInternal("Content-Type", "application/x-www-form-urlencoded"); else #endif // FIXME: this should include the charset used for encoding. setRequestHeaderInternal("Content-Type", "application/xml"); } // FIXME: According to XMLHttpRequest Level 2, this should use the Document.innerHTML algorithm // from the HTML5 specification to serialize the document. String body = createMarkup(document); // FIXME: this should use value of document.inputEncoding to determine the encoding to use. TextEncoding encoding = UTF8Encoding(); m_requestEntityBody = FormData::create(encoding.encode(body.characters(), body.length(), EntitiesForUnencodables)); if (m_upload) m_requestEntityBody->setAlwaysStream(true); } createRequest(ec); }
void XMLHttpRequest::send(Blob* body, ExceptionCode& ec) { if (!initSend(ec)) return; if (m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) { const String& contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { const String& blobType = body->type(); if (!blobType.isEmpty() && isValidContentType(blobType)) setRequestHeaderInternal("Content-Type", blobType); else { // From FileAPI spec, whenever media type cannot be determined, empty string must be returned. setRequestHeaderInternal("Content-Type", ""); } } // FIXME: add support for uploading bundles. m_requestEntityBody = FormData::create(); if (body->isFile()) m_requestEntityBody->appendFile(toFile(body)->path()); #if ENABLE(BLOB) else m_requestEntityBody->appendBlob(body->url()); #endif } createRequest(ec); }
void XMLHttpRequest::send(Blob* body, ExceptionState& exceptionState) { WTF_LOG(Network, "XMLHttpRequest %p send() Blob '%s'", this, body->uuid().utf8().data()); if (!initSend(exceptionState)) return; if (areMethodAndURLValidForSend()) { if (getRequestHeader("Content-Type").isEmpty()) { const String& blobType = body->type(); if (!blobType.isEmpty() && isValidContentType(blobType)) setRequestHeaderInternal("Content-Type", AtomicString(blobType)); else { // From FileAPI spec, whenever media type cannot be determined, empty string must be returned. setRequestHeaderInternal("Content-Type", ""); } } // FIXME: add support for uploading bundles. m_requestEntityBody = FormData::create(); if (body->hasBackingFile()) m_requestEntityBody->appendFile(toFile(body)->path()); else m_requestEntityBody->appendBlob(body->uuid(), body->blobDataHandle()); } createRequest(exceptionState); }
void XMLHttpRequest::send(Document* document, ExceptionCode& ec) { ASSERT(document); if (!initSend(ec)) return; // 03/31/2011 - abaldeva : Change the request to execute for any protocol except file. This allows for using XmlHttpRequest object with Custom // protocols. //if (m_method != "GET" && m_method != "HEAD" && (m_url.protocolIs("http") || m_url.protocolIs("https"))) { if (m_method != "GET" && m_method != "HEAD" && !m_url.protocolIs("file")) { String contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { #if ENABLE(DASHBOARD_SUPPORT) Settings* settings = m_doc->settings(); if (settings && settings->usesDashboardBackwardCompatibilityMode()) setRequestHeaderInternal("Content-Type", "application/x-www-form-urlencoded"); else #endif // FIXME: this should include the charset used for encoding. setRequestHeaderInternal("Content-Type", "application/xml"); } // FIXME: According to XMLHttpRequest Level 2, this should use the Document.innerHTML algorithm // from the HTML5 specification to serialize the document. String body = createMarkup(document); // FIXME: this should use value of document.inputEncoding to determine the encoding to use. TextEncoding encoding = UTF8Encoding(); m_requestEntityBody = FormData::create(encoding.encode(body.characters(), body.length(), EntitiesForUnencodables)); } createRequest(ec); }
void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState) { WTF_LOG(Network, "XMLHttpRequest %p send() Document %p", this, document); ASSERT(document); if (!initSend(exceptionState)) return; if (areMethodAndURLValidForSend()) { if (getRequestHeader("Content-Type").isEmpty()) { // FIXME: this should include the charset used for encoding. setRequestHeaderInternal("Content-Type", "application/xml"); } // FIXME: According to XMLHttpRequest Level 2, this should use the Document.innerHTML algorithm // from the HTML5 specification to serialize the document. 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)); if (m_upload) m_requestEntityBody->setAlwaysStream(true); } createRequest(exceptionState); }
void XMLHttpRequest::send(DOMFormData* body, ExceptionCode& ec) { if (!initSend(ec)) return; if (m_method != "GET" && m_method != "HEAD" && m_url.protocolInHTTPFamily()) { m_requestEntityBody = FormData::createMultiPart(*body, document()); String contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { contentType = "multipart/form-data; boundary="; contentType += m_requestEntityBody->boundary().data(); setRequestHeaderInternal("Content-Type", contentType); } } createRequest(ec); }
void XMLHttpRequest::send(DOMFormData* body, ExceptionState& exceptionState) { WTF_LOG(Network, "XMLHttpRequest %p send() DOMFormData %p", this, body); if (!initSend(exceptionState)) return; if (areMethodAndURLValidForSend()) { m_requestEntityBody = body->createMultiPartFormData(body->encoding()); if (getRequestHeader("Content-Type").isEmpty()) { AtomicString contentType = AtomicString("multipart/form-data; boundary=", AtomicString::ConstructFromLiteral) + m_requestEntityBody->boundary().data(); setRequestHeaderInternal("Content-Type", contentType); } } createRequest(exceptionState); }
void XMLHttpRequest::send(DOMFormData* body, ExceptionCode& ec) { if (!initSend(ec)) return; if (m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) { m_requestEntityBody = FormData::createMultiPart(*(static_cast<FormDataList*>(body)), body->encoding(), document()); m_requestEntityBody->generateFiles(document()); String contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { contentType = makeString("multipart/form-data; boundary=", m_requestEntityBody->boundary().data()); setRequestHeaderInternal("Content-Type", contentType); } } createRequest(ec); }
void XMLHttpRequest::send(DOMFormData* body, ExceptionCode& ec) { if (!initSend(ec)) return; if (m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) { m_requestEntityBody = FormData::createMultiPart(*(static_cast<FormDataList*>(body)), body->encoding(), document()); // We need to ask the client to provide the generated file names if needed. When FormData fills the element // for the file, it could set a flag to use the generated file name, i.e. a package file on Mac. m_requestEntityBody->generateFiles(document()); String contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { contentType = makeString("multipart/form-data; boundary=", m_requestEntityBody->boundary().data()); setRequestHeaderInternal("Content-Type", contentType); } } createRequest(ec); }
void XMLHttpRequest::send(Blob* body, ExceptionCode& ec) { if (!initSend(ec)) return; if (m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) { const String& contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { const String& blobType = body->type(); if (!blobType.isEmpty() && isValidContentType(blobType)) setRequestHeaderInternal("Content-Type", blobType); else { // From FileAPI spec, whenever media type cannot be determined, empty string must be returned. setRequestHeaderInternal("Content-Type", ""); } } m_requestEntityBody = FormData::create(); m_requestEntityBody->appendBlob(body->url()); } createRequest(ec); }
void XMLHttpRequest::send(const String& body, ExceptionState& exceptionState) { WTF_LOG(Network, "XMLHttpRequest %p send() String '%s'", this, body.utf8().data()); if (!initSend(exceptionState)) return; if (!body.isNull() && areMethodAndURLValidForSend()) { String contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { setRequestHeaderInternal("Content-Type", "text/plain;charset=UTF-8"); } else { replaceCharsetInMediaType(contentType, "UTF-8"); m_requestHeaders.set("Content-Type", AtomicString(contentType)); } m_requestEntityBody = FormData::create(UTF8Encoding().encode(body, WTF::EntitiesForUnencodables)); if (m_upload) m_requestEntityBody->setAlwaysStream(true); } createRequest(exceptionState); }
void XMLHttpRequest::send(const String& body, ExceptionCode& ec) { if (!initSend(ec)) return; if (!body.isNull() && m_method != "GET" && m_method != "HEAD" && (m_url.protocolIs("http") || m_url.protocolIs("https"))) { String contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { #if ENABLE(DASHBOARD_SUPPORT) Settings* settings = m_doc->settings(); if (settings && settings->usesDashboardBackwardCompatibilityMode()) setRequestHeaderInternal("Content-Type", "application/x-www-form-urlencoded"); else #endif setRequestHeaderInternal("Content-Type", "application/xml"); } m_requestEntityBody = FormData::create(UTF8Encoding().encode(body.characters(), body.length(), EntitiesForUnencodables)); if (m_upload) m_requestEntityBody->setAlwaysStream(true); } createRequest(ec); }
void XMLHttpRequest::send(const String& body, ExceptionCode& ec) { if (!m_doc) return; if (m_state != Loading) return; // FIXME: Should this abort instead if we already have a m_job going? if (m_job) return; m_aborted = false; if (!body.isNull() && m_method != "GET" && m_method != "HEAD" && (m_url.protocol().lower() == "http" || m_url.protocol().lower() == "https")) { String contentType = getRequestHeader("Content-Type"); String charset; if (contentType.isEmpty()) setRequestHeader("Content-Type", "application/xml", ec); else charset = getCharset(contentType); if (charset.isEmpty()) charset = "UTF-8"; TextEncoding m_encoding = TextEncoding(charset.deprecatedString().latin1()); if (!m_encoding.isValid()) // FIXME: report an error? m_encoding = TextEncoding(UTF8Encoding); m_job = new TransferJob(m_async ? this : 0, m_method, m_url, m_encoding.fromUnicode(body.deprecatedString())); } else { // FIXME: HEAD requests just crash; see <rdar://4460899> and the commented out tests in http/tests/xmlhttprequest/methods.html. if (m_method == "HEAD") m_method = "GET"; m_job = new TransferJob(m_async ? this : 0, m_method, m_url); } if (m_requestHeaders.length()) m_job->addMetaData("customHTTPHeader", m_requestHeaders); if (!m_async) { Vector<char> data; KURL finalURL; DeprecatedString headers; { // avoid deadlock in case the loader wants to use JS on a background thread KJS::JSLock::DropAllLocks dropLocks; data = ServeSynchronousRequest(cache()->loader(), m_doc->docLoader(), m_job, finalURL, headers); } m_job = 0; processSyncLoadResults(data, finalURL, headers); return; } // Neither this object nor the JavaScript wrapper should be deleted while // a request is in progress because we need to keep the listeners alive, // and they are referenced by the JavaScript wrapper. ref(); { KJS::JSLock lock; gcProtectNullTolerant(KJS::ScriptInterpreter::getDOMObject(this)); } m_job->start(m_doc->docLoader()); }
void XMLHttpRequest::send(const String& body, ExceptionCode& ec) { if (!m_doc) return; if (m_state != Open) { ec = INVALID_STATE_ERR; return; } // FIXME: Should this abort or raise an exception instead if we already have a m_loader going? if (m_loader) return; m_aborted = false; ResourceRequest request(m_url); request.setHTTPMethod(m_method); if (!body.isNull() && m_method != "GET" && m_method != "HEAD" && (m_url.protocol().lower() == "http" || m_url.protocol().lower() == "https")) { String contentType = getRequestHeader("Content-Type"); if (contentType.isEmpty()) { ExceptionCode ec = 0; setRequestHeader("Content-Type", "application/xml", ec); ASSERT(ec == 0); } // FIXME: must use xmlEncoding for documents. String charset = "UTF-8"; TextEncoding m_encoding(charset); if (!m_encoding.isValid()) // FIXME: report an error? m_encoding = UTF8Encoding(); request.setHTTPBody(PassRefPtr<FormData>(new FormData(m_encoding.encode(body.characters(), body.length())))); } if (m_requestHeaders.size() > 0) request.addHTTPHeaderFields(m_requestHeaders); if (!m_async) { Vector<char> data; ResourceError error; ResourceResponse response; { // avoid deadlock in case the loader wants to use JS on a background thread #ifdef __OWB_JS__ KJS::JSLock::DropAllLocks dropLocks; if (m_doc->frame()) m_doc->frame()->loader()->loadResourceSynchronously(request, error, response, data); #endif } m_loader = 0; if (error.isNull()) processSyncLoadResults(data, response); else ec = NETWORK_ERR; return; } // Neither this object nor the JavaScript wrapper should be deleted while // a request is in progress because we need to keep the listeners alive, // and they are referenced by the JavaScript wrapper. ref(); { #ifdef __OWB_JS__ KJS::JSLock lock; gcProtectNullTolerant(KJS::ScriptInterpreter::getDOMObject(this)); #endif } // create can return null here, for example if we're no longer attached to a page. // this is true while running onunload handlers // FIXME: Maybe create can return false for other reasons too? m_loader = SubresourceLoader::create(m_doc->frame(), this, request); }